find and replace in multiple files using PHP

六眼飞鱼酱① 提交于 2019-12-25 07:37:32

问题


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?


回答1:


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.




回答2:


replace this code:

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

with:

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


来源:https://stackoverflow.com/questions/24592503/find-and-replace-in-multiple-files-using-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!