Re: string replace in files
| From: | Justin Patrin | Date: | Fri, 30 Apr 2004 20:25:14 +0000 |
| Subject: | Re: string replace in files | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-185074@lists.php.net to get a copy of this message | ||
Steve Buehler wrote:
I am trying to write a script that will replace a string in a file. Actually, about 3000 files. And I am stuck. I can get the list of files, but then I pretty much become stuck. I wanted to try str_ireplace (not sure if that is what I should use or not), but I can't even get far enough to do that. I am hoping that someone out there has an easy response to this. Below is the code that I have so far. Thanks Steve #!/usr/bin/php <? $strtoreplace="require \"http://www.domain.com/"; $replacewithstring="require \"/home/domain/www/"; replacestring(); function replacestring(){ GLOBAL $strtoreplace,$replacewithstring;^_^ You could use PEAR's File_SearchReplace. http://pear.php.net/package/File_SearchReplace A few lines of code and it's all done for you. :-) -- paperCrane <Justin Patrin>$FILES=array(} ?>ls -1 */*|grep .php); foreach($FILES as $value){ if($value){ echo "file $value\n"; $handle=fopen($value,'a'); } }