溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

批量修改php文件的方法

發(fā)布時(shí)間:2020-09-08 09:54:14 來源:億速云 閱讀:133 作者:小新 欄目:編程語言

這篇文章將為大家詳細(xì)講解有關(guān)批量修改php文件的方法,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

批量修改php文件的方法:首先打開目錄;然后列出所有文件并去掉【.】和【..】,代碼為【if($file!='.' &&$file!='..')】;接著賦值給數(shù)組,代碼為【$arr_file[]=$file】,最后輸出結(jié)果。

批量修改php文件的方法

批量修改php文件的方法:

<?php
 $folder="D:\U";
 //打開目錄
$fp=opendir($folder);
$find=array("admanage","admin","adtype","maintype","diymenu","getmode","goods","goodsattr","goodsbrand","goodsflag","goodsorder","goodsreview","goodstype","infoflag","infoclass","infoimg","infolist","job","lnk","member","message","paymode","postarea","postmode","soft","vote","webconfig","weblink","weblinktype","info");
$replace=array("admanage_en","admin_en","adtype_en","maintype_en","diymenu_en","getmode_en","goods_en","goodsattr_en","goodsbrand_en","goodsflag_en","goodsorder_en","goodsreview_en","goodstype_en","infoflag_en","infoclass_en","infoimg_en","infolist_en","job_en","lnk_en","member_en","message_en","paymode_en","postarea_en","postmode_en","soft_en","vote_en","webconfig_en","weblink_en","weblinktype_en","info_en");
$cnt=count($find);
 //閱讀目錄
while(false!=$file=readdir($fp))
{
//列出所有文件并去掉'.'和'..'
    if($file!='.' &&$file!='..')
    {
        //$file="$folder/$file";
        $file="$file";
        //賦值給數(shù)組
        $arr_file[]=$file;
        }
}
 //輸出結(jié)果
 if(is_array($arr_file))
 {
    while(list($key,$value)=each($arr_file))
    {
        $name=strrev(substr(strrev($value),4));
        $fw = fopen($folder.'\\'.$name."_en.php","w");
        $fr = fopen($folder.'\\'.$value, "r");
        while (!feof($fr))
        {
               $line = fgets($fr);
               if(strstr($line,"#@__"))
            {
                for($i=0;$i<$cnt;$i++)
                    if(strstr($line,$find[$i]))
                    {
                        $line=str_replace($find[$i],$replace[$i],$line);
                        break;
                    }
            }
            fputs($fw,$line);
        }
        fclose($fr);
        fclose($fw);
    }
   }
//關(guān)閉目錄
closedir($fp);
?>

關(guān)于批量修改php文件的方法就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI