「プログラミング]My Tips (あるいは車輪の再発明)
- 文字列の引き算[PHP]
-
PHPで「文字列の足し算」は演算子 "." を用いて $var1.$var2 である。
引き算は次のようなソースを書くと実現できないわけではない。
$tmp= explode(引き算したい文字列,対象となる文字列); $result= implode("",$tmp);
ただし「対象となる文字列」中の「引き算したい文字列」を全部消すので注意されたい。 - Order Allow, Deny[Apache]
- 説明のページmod_authz_host - Apache HTTP サーバ バージョン 2.2
- 連続するスペースに対する explode [PHP]
-
区切り文字がスペースの時に explode() でいらいらしたので作った[2007.2.4]
function explode_by_spaces($string){ $tmp=eregi_replace("[[:space:]]{1,}"," ",$string); return explode(" ",$tmp); }
- 行毎に配列に格納して返す file_get_contents [PHP]
-
いらいらしたので作った[2007.2.4]
function file_get_contents_by_line($file){ $handle = @fopen($file,"r"); if ($handle) { while (!feof($handle)) { $buffer[] = fgets($handle); } fclose($handle); } return $buffer; }
[2007.6.3]某所では fgets() がうまく動かなかったので、次のスクリプトを書いたfunction file_get_contents_by_line($file){ $filesize=filesize($file); $handle = @fopen($file,'r'); if ($handle) { $file_contents= fread($handle,$filesize); fclose($handle); }else{ exit("cannot open the file"); } $file_contents= str_replace("\r\n","\n",$file_contents); //↑Windowsの改行コードの変更 return preg_split("(\n)",$file_contents); }
- 文字列の書き換えリスト[PHP]
- [2007.6.10]配列のキーと内容の表記法を「aをbに」「cをdに」という書き換えの表記に使えないかなと思って作った
$str_replace_list=array( "a"=>"b", "c" => "d" ); $string= str_replace(array_keys($str_replace_list),$str_replace_list,$string);
- php-win.exeとは[PHP]
- [2007.8.16]PHP: コマンドラインの使用法 - Manualを見よ。