string replace in files
| From: | Steve Buehler | Date: | Fri, 30 Apr 2004 16:03:38 +0000 |
| Subject: | string replace in files | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-185054@lists.php.net to get a copy of this message | ||
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;
$FILES=array(ls -1 */*|grep .php);
foreach($FILES as $value){
if($value){
echo "file $value\n";
$handle=fopen($value,'a');
}
}
}
?>