つっこみ

つっこみ欄にコメントを記載して[つっこむ]ボタンを押してください。
お名前欄の記載は省略できます。

お名前 :
←ここのテキストボックスはスパム対策用なので何も入力しないでください
つっこみ :

[キャンセル]


つっこみ先の記事

・ PHP覚え書き

PHPにはHTMLによる完璧な入門書兼リファレンスマニュアルがあるのですが、関数名はわかってるけどどこに分類されているのかわからない(^^;)ときがよくあるので、ちょっと覚え書きと使用例。

string urlencode ( string str)
文字列のURLエンコード
echo "<a href=\"foo.php?thisURL=",urlencode($REQUEST_URI),"\">・・・</a>\n";
string addslashes ( string str)
文字列をスラッシュでクォートする
$s = addslashes($insecure_string);
pg_exec($con,"select count(*) from _table where columns='$s'");
string escapeshellcmd ( string command)
シェルのメタ文字をエスケープする
# escapeshellarg との使い分けがいまいち理解できていない(^^;)
$s = '`cat /etc/passwd`';
$s = escapeshellcmd($s);
echo system("man -p cat $s");
string implode ( string glue, array pieces)
配列要素を文字列により連結する
$ar = array("sex='男の子'" , "name='しいねちゃん'" , "skill='家事'");
$str = implode(" and ",$ar);
pg_exec($con,"select * from _table where $str");
string date ( string format, int [timestamp])
ローカルの日付/時刻を書式化する
$weekarray=array(0=>"日","月","火","水","木","金","土");
$dt=time();
echo date("Y/m/d H:i:s",$dt);
echo $weekarray[date("w",$dt)];
// last-Modifiedヘッダを入れる
header("Last-Modified: " . gmdate("D, d M Y H:i:s",$dt) . " GMT");
array getimagesize ( string filename, array [imageinfo])
JPEG、GIF、PNG、SWF画像の大きさを取得する
// <img>に width/heightを入れる(ひとりごとこーなーのソースから引用^^;)
$body = addslashes(preg_replace_callback('/(<img src=\"[^>]*>)/is',"repsub1",stripslashes($body)));

function repsub1($ar)
{
    $text = $ar[0];
    if (!preg_match('/width=/is',$text) && !preg_match('/height=/is',$text) ) {
        $text = preg_replace_callback('/(<img src=\")([^\">]*)(\")(.*>)/is',"repsub2",$text);
    }
    return $text;
}

function repsub2($ar)
{
    $s = "";

    if (file_exists($ar[2])) {
        $sz = getimagesize($ar[2]);
        if (strlen($sz[3])>0) {
            array_shift($ar); //一つ捨てる
            $s = "";
            $s .= array_shift($ar); // <img src="
            $s .= array_shift($ar); // ファイル名
            $s .= array_shift($ar); // "
            $s .= " ${sz[3]} ";
            foreach($ar as $val) {    //残り全部
                $s .= $val;
            }
            return $s;
        }
    }
    return $ar[0];
}
ここにメモしたこと自体を忘れそうな気がしますが(笑)

■この記事への permanent link URL(下にいくほどファイルサイズが大きくなります)
  http://toriyu.jp/hitorigoto/id1043.html
  http://toriyu.jp/hitorigoto/2003-12-16.html (1日分)
  http://toriyu.jp/hitorigoto/2003-12.html#id1043 (1ヶ月分)