php 批量修改文件,如何批量修改php文件

如何批量修改php文件2020-09-13 00:37:11

bebc856779dc5b3c783276160d8be173.png

批量修改php文件的方法:首先打开目录;然后列出所有文件并去掉【.】和【..】,代码为【if($file!='.' &&$file!='..')】;接着赋值给数组,代码为【$arr_file[]=$file】,最后输出结果。

【相关学习推荐: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";

//赋值给数组

$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

if(strstr($line,$find[$i]))

{

$line=str_replace($find[$i],$replace[$i],$line);

break;

}

}

fputs($fw,$line);

}

fclose($fr);

fclose($fw);

}

}

//关闭目录

closedir($fp);

?>

想了解更多编程学习,敬请关注php培训栏目!

特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。

Tags 标签

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值