function getfiles($path){
static $success=0;
static $fail=0;
foreach(scandir($path) as $afile)
{
if($afile == 'system')continue;
if($afile=='.'||$afile=='..') continue;
if(is_dir($path.'/'.$afile))
{
getfiles($path.'/'.$afile);
} else {
$fileName = $path.'/'.$afile;
$info = pathinfo($fileName);
if($info['extension'] ==='php'){
$content = file_get_contents($fileName);
if(!empty($content)){
$content = preghttp($content);
$content = preghttps($content);
$content = pregphp($content);
$content = removeComment($content);
$content =httpback($content);
$content = httpsback($content);
$content = phpsback($content);
if(file_put_contents($fileName,$content)){
$success++;
echo $fileName.":delete success\n";
}else{
$fail++;
echo $fileName.":delete file\n";
}
}
}
}
}
echo "replacess over\n";
echo "success:".$success.",fail:".$fail."\n";
}
function removeComment($content){
return preg_replace("/(\/\*.*?\*\/)|(\/\*\*.*?\*\/)|(\/\/.*?\n)/s","\n",str_replace(array("\r\n","\r"),"\n", $content));
}
function preghttp($content){
return preg_replace("/(http:\/\/)/s",'O网页链接
}
function preghttps($content){
return preg_replace("/(https:\/\/)/s",'O网页链接
}
function httpback($content){
return preg_replace("/http:///s",'O网页链接
}
function httpsback($content){
return preg_replace("/http://0S/s",'O网页链接
}
function pregphp($content){
return preg_replace("/(php:\/\/)/s",'php://',$content);
}
function phpsback($content){
return preg_replace("/php:///s",'php://',$content);
}
网友评论