美文网首页
php循环遍历所有文件清空注释

php循环遍历所有文件清空注释

作者: 宝_0350 | 来源:发表于2020-04-05 12:54 被阅读0次

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);

}

相关文章

网友评论

      本文标题:php循环遍历所有文件清空注释

      本文链接:https://www.haomeiwen.com/subject/jrkuphtx.html