<?xml version="1.0" encoding="utf-8"?>
<!-- generator="FeedCreator 1.7.2-ppt DokuWiki" -->
<?xml-stylesheet href="https://tm.root-n.com/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel>
        <title>Tipsというかメモ programming:php:idiom</title>
        <description></description>
        <link>https://tm.root-n.com/</link>
        <lastBuildDate>Wed, 19 Nov 2025 03:14:47 +0900</lastBuildDate>
        <generator>FeedCreator 1.7.2-ppt DokuWiki</generator>
        <image>
            <url>https://tm.root-n.com/lib/images/favicon.ico</url>
            <title>Tipsというかメモ</title>
            <link>https://tm.root-n.com/</link>
        </image>
        <item>
            <title>PHP :: イディオム / array_walk_recursive と create_function で配列の再帰処理</title>
            <link>https://tm.root-n.com/programming:php:idiom:array_walk_recursive_create_function</link>
            <description>array_walk_recursive と create_function を組み合わせて、少ないコード量で配列の再帰処理を実現します。

二次元や三次元の多次元配列のすべての要素に対して、同一の処理を実行したい時にとても便利。</description>
        <category>programming:php:idiom</category>
            <pubDate>Sun, 21 Apr 2019 15:00:29 +0900</pubDate>
        </item>
        <item>
            <title>PHP :: イディオム / 年齢計算</title>
            <link>https://tm.root-n.com/programming:php:idiom:calc_age</link>
            <description>以下の公式で簡単に年齢計算ができるそうです。


&lt;?php

$today = date('Ymd');
$birthday = '19810203'; // yyyymmdd

echo (int)(($today - $birthday) / 10000);

?&gt;</description>
        <category>programming:php:idiom</category>
            <pubDate>Wed, 04 Nov 2009 17:52:53 +0900</pubDate>
        </item>
        <item>
            <title>PHP :: イディオム / 月末の日付を取得する</title>
            <link>https://tm.root-n.com/programming:php:idiom:end_of_month</link>
            <description>&lt;?php

// format文字：t = 指定した月の日数(28 から 31)を返却。
echo '2007年02月の月末：'.date('Y/m/t', strtotime('2007-02')).PHP_EOL;
echo '2008年02月の月末：'.date('Y/m/t', strtotime('2008-02'));

?&gt;


▼結果


2007年02月の月末：2007/02/28
2008年02月の月末：2008/02/29</description>
        <category>programming:php:idiom</category>
            <pubDate>Wed, 24 Dec 2008 17:03:23 +0900</pubDate>
        </item>
        <item>
            <title>PHP :: イディオム / 閏年(うるう年)の判定</title>
            <link>https://tm.root-n.com/programming:php:idiom:is_leap_year</link>
            <description>function isLeapYear($year)
{
    return ((($year % 4) == 0) &amp;&amp; ((($year % 100) != 0) || (($year % 400) == 0)));
}</description>
        <category>programming:php:idiom</category>
            <pubDate>Sun, 16 Mar 2008 22:48:14 +0900</pubDate>
        </item>
        <item>
            <title>PHP :: イディオム / ブラウザで逐一出力を実現する</title>
            <link>https://tm.root-n.com/programming:php:idiom:one_by_one_output</link>
            <description>PHP は通常、アウトプットバッファリングが有効になっているため、ブラウザから以下のようなスクリプトを実行しても逐一表示されません。


&lt;?php

for ($i = 0; $i &lt; 50; $i++) {
    echo '|';
    sleep(1);
}

?&gt;</description>
        <category>programming:php:idiom</category>
            <pubDate>Thu, 16 Apr 2009 19:05:51 +0900</pubDate>
        </item>
        <item>
            <title>PHP :: イディオム / postgresql のエラーチェック</title>
            <link>https://tm.root-n.com/programming:php:idiom:pg_result_status</link>
            <description>参照系のエラーチェック (ストアドも含む)



$res = $conn-&gt;pg_query('SELECT * .....')
//$res はリザルトオブジェクト
if (pg_result_status($res) == PGSQL_TUPLES_OK) {
	何かの処理
} else {
	エラー処理
}





更新系のエラーチェック</description>
        <category>programming:php:idiom</category>
            <pubDate>Sun, 16 Mar 2008 22:48:14 +0900</pubDate>
        </item>
        <item>
            <title>PHP :: イディオム / プロトコル/ラッパー</title>
            <link>https://tm.root-n.com/programming:php:idiom:protocol_wrapper</link>
            <description>以下は、file_get_contents や file_put_contents の引数として利用できます。

HTTP と HTTPS

&lt;http://jp.php.net/manual/ja/wrappers.http.php&gt;



http://example.com
http://example.com/file.php?var1=val1&amp;var2=val2
http://user:password@example.com
https://example.com
https://example.com/file.php?var1=val1&amp;var2=val2
https://user:password@example.com</description>
        <category>programming:php:idiom</category>
            <pubDate>Wed, 06 May 2009 15:45:09 +0900</pubDate>
        </item>
        <item>
            <title>PHP :: イディオム / ディレクトリ配下のファイル名一覧を取得する</title>
            <link>https://tm.root-n.com/programming:php:idiom:readdir</link>
            <description>&lt;?php

// 'LOG_DIR'の定義
define('LOG_DIR', '/path/to/logs/');

$dir = @opendir(LOG_DIR);
if ($dir === false) {
    exit('can not open directory.');
}

// 拡張子が .log のみ取得
$ext = '.log';
$files = array();
while($file = readdir($dir)) {
    if(is_file(LOG_DIR.$file) &amp;&amp; preg_match(&quot;/$ext$/&quot;, LOG_DIR.$file)) {
        $files[] = $file;
    }
}

var_dump($files);

?&gt;</description>
        <category>programming:php:idiom</category>
            <pubDate>Sun, 16 Mar 2008 22:48:14 +0900</pubDate>
        </item>
        <item>
            <title>PHP :: イディオム / 再帰関数の例</title>
            <link>https://tm.root-n.com/programming:php:idiom:recursive_function</link>
            <description>*  与えられた引数の値を htmlspecialchars して返す
	*  引数の型は string, array どちらでもよい


function sanitize($value)
{
    if(is_array($value)){
        $sanitized_array = array();
        foreach($value as $k =&gt; $v){
            $sanitized_array[$k] = sanitize($v);
        }
        return $sanitized_array;
    } else {
        return htmlspecialchars($value);
    }
}</description>
        <category>programming:php:idiom</category>
            <pubDate>Tue, 24 Mar 2009 00:10:56 +0900</pubDate>
        </item>
        <item>
            <title>PHP :: イディオム / 標準入力(STDIN)から値を読み取る</title>
            <link>https://tm.root-n.com/programming:php:idiom:stdin</link>
            <description>$fp = fopen('php://stdin', 'r');

// fopen に失敗した場合、これを記述しておかないと下の while で無限ループが発生する。
if ( ! $fp) exit(&quot;Error\n&quot;);

$stdin = '';
while( ! feof($fp)) {
    $stdin .= fgets($fp, 4096);
}
fclose($fp);</description>
        <category>programming:php:idiom</category>
            <pubDate>Sun, 16 Mar 2008 22:48:15 +0900</pubDate>
        </item>
        <item>
            <title>PHP :: イディオム / strtotime を使った相対的な日付</title>
            <link>https://tm.root-n.com/programming:php:idiom:strtotime</link>
            <description>strtotime

英文形式の日付を Unix タイムスタンプに変換する 


int strtotime ( string $time [, int $now ] )


time

パースする文字列。PHP 5.0.0 より前のバージョンではマイクロ秒を含めることはできませんでした。 PHP 5.0.0 以降ではマイクロ秒を含めることが可能ですが、その値は無視されます。



now

返される値を計算するために使用されるタイムスタンプ。</description>
        <category>programming:php:idiom</category>
            <pubDate>Wed, 15 May 2019 11:41:39 +0900</pubDate>
        </item>
    </channel>
</rss>
