Skip to content

Instantly share code, notes, and snippets.

@slacken
Created December 12, 2012 06:57
Show Gist options
  • Select an option

  • Save slacken/4265632 to your computer and use it in GitHub Desktop.

Select an option

Save slacken/4265632 to your computer and use it in GitHub Desktop.
replace all php file's content in current dir
<?php
$pattern = '/聚摊网/';
$target = '聚城';
function startdir($dir){
$handle = opendir($dir);
if($handle == false)return;
while (false !== ($file = readdir($handle))) {
$path = $dir.$file;
if(is_file($path) && substr($file,-4,4) == '.php'){
$content = file_get_contents($path);
file_put_contents($path,preg_replace($pattern,$target,$content));
echo $path."\n";
}
elseif(is_dir($path) && substr($file, 0,1) != '.'){
startdir($path.'/');
}
}
}
startdir('./');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment