From: "Steve Buehler" <[EMAIL PROTECTED]>

> 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";

$content = file_get_contents($value);
$content = str_replace($strtoreplace,$replacewithstring,$content);
$fp = fopen($value,'w');
fwrite($fp,$content);
fclose($fp);

>                  }
>          }
> }
> ?>

You could use glob() to get the list of files, too.

$FILES = glob('*.php');

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to