您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關批量修改php文件的方法,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
批量修改php文件的方法:首先打開目錄;然后列出所有文件并去掉【.】和【..】,代碼為【if($file!='.' &&$file!='..')】;接著賦值給數組,代碼為【$arr_file[]=$file】,最后輸出結果。
批量修改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"; //賦值給數組 $arr_file[]=$file; } } //輸出結果 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); } } //關閉目錄 closedir($fp); ?>
關于批量修改php文件的方法就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。