PHP批量更改文件内容
摘要:可以将某个文件夹内的所有特定文件中的内容改为其它内容...
$scanDir = '/home/wwwroot/default/zb_users/theme/video'; //文件夹$ext = array('php','js','css','txt','xml'); //需要更改的文件后缀$text = 'dedevv'; //要更改的字符$newText = 'newstr'; //新字符function dirfolder($dir){
global $ext,$text,$newText;
foreach (scandir($dir) as $value) {
if ($value != '.' && $value != '..'){
$path = $dir.'/'.$value;
if (is_dir($path)){
dirfolder($path);
}else{
if (preg_match('/\.('.implode('|',$ext).')$/',$path)){
$str = file_get_contents($path);
if (strpos($str,$text) !== false){
$str = str_replace($text,$newText,$str);
file_put_contents($path,$str);
}
}
}
}
}
}dirfolder($scanDir);飞翔大橙子授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!
