php言語 コンテンツを一括編集

サンプルコード:

function find_all_dir( $dir,$research=array(), $replace=array()){
//ディレクトリ内のすべてのファイルを見つける
$dh = opendir( $dir );
while ( $file = readdir( $dh ) ) {
if ( $file != “." && $file != “.." ) {
$fullpath = $dir . “/" . $file;
if ( !is_dir( $fullpath ) ) {
$f=fopen($fullpath, 'r’);
$text=fread($f, filesize($fullpath));
//コンテンツを編集
$text=str_replace($research, $replace , $text);
//結果を判断
$result=file_put_contents($fullpath, $text);
} else {
find_all_dir( $fullpath );
}
}
}
closedir( $dh );
}

Source

Posted by arkgame