批量修改内容
时间:2021-07-01 10:21:17
帮助过:4人阅读
批量修改文件内容 $dir路径 $research 被修改内容 $replace 修改内容
- 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 );
- }
|