使用PHP查找并替换多个文件 [英] find and replace in multiple files using PHP

查看:298
本文介绍了使用PHP查找并替换多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文件夹包含大约500个文件(html)。
每个文件都包含这个脚本

 < script type =text / javascript><! - 
google_ad_client =??????;
/ * unit1 * /
google_ad_slot =??????;
google_ad_width = 120;
google_ad_height = 90;
// - >
< / script>

我想用这个替换上面的代码

 < script type =text / javascriptsrc =/ wp-content / themes / twentyfourteen / open.js>< / script> 

我用这个代码>>很好

http://pastebin.com/wuWupgBg



这只能在PHP中找到并替换,而不能在HTML中找到并替换。
任何人都可以找到并替换html文件?

解决方案

不是我们在这里做什么,但我会如果(is_file($ path)&& substr($ path,-3),那么你可能会改变第17行:

  )=='php'&& substr($ path,-17)!='ChangePHPText.php'){


$ ($ path)&& substr($ path,-4)b $ b

=='html'&& substr($ path,-17)!='ChangePHPText.php'){

虽然说实话,如果你做了很多的文本更改,你可能会发现一个文本编辑器,可以在文件中进行字符串替换,速度更快。


My folder contains about 500 files (html). Each files contain this script

<script type="text/javascript"><!--
google_ad_client = "??????";
/* unit1 */
google_ad_slot = "??????";
google_ad_width = 120;
google_ad_height = 90;
//-->
</script>

I want to replace above code with this

<script type="text/javascript" src="/wp-content/themes/twentyfourteen/open.js"></script>

I used this code >>is good

http://pastebin.com/wuWupgBg

This find and replace in php only but no find and replace in html. Can anyone make it find and replace in html files?

解决方案

Not really what we do here, but I would think you would just change line 17:

if( is_file( $path ) && substr($path, -3)=='php' && substr($path, -17) != 'ChangePHPText.php'){

to

if( is_file( $path ) && substr($path, -4)=='html' && substr($path, -17) != 'ChangePHPText.php'){

Though honestly, if you're doing that much text change, you may find a text editor that does string replacement in files to be much faster.

这篇关于使用PHP查找并替换多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆