使用PHP在多个文件中查找和替换

时间:2014-07-06 03:38:59

标签: php file replace find

我的文件夹包含大约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/javascript" src="/wp-content/themes/twentyfourteen/open.js"></script>

我使用此代码&gt;&gt;很好

http://pastebin.com/wuWupgBg

这只在php中查找并替换,但在html中找不到并替换。 任何人都可以在html文件中查找和替换它吗?

2 个答案:

答案 0 :(得分:1)

替换此代码:

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

使用:

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

答案 1 :(得分:0)

这不是我们在这里做的,但我认为你只会改变第17行:

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

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

虽然老实说,如果你正在进行那么多的文本更改,你可能会发现一个文本编辑器可以更快地在文件中进行字符串替换。

相关问题