傅令江的光影色彩世界
php批量修改文件内容函数
2014-8-23 令狐江
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 );
}
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容