Some editors let you find/replace in files in a certain folder.  That might
be easier.  I know UltraEdit let you do this and it only takes a few
minutes.  To me, that is much less labor-intensive than trying to write code
to do it, unless you're trying to learn things while you do it. :-)


-----Original Message-----
From: Naintara Jain [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, June 27, 2002 2:46 AM
To: Php-General@Lists. Php. Net
Subject: [PHP] FOXED - no success in replacing file content using
fgets/fputs and str_replace

I need to replace some html code in about 100 files.

Wanted to do this through code, and am using fgets() to get a line at a time
from the file, this string is saved in variable $line.

Then I check for the occurrence of the search string in $line using
strpos(). If found, I echo some statements, and I wanted to replace the
"search" text with "replace" text using str_replace(). The strange thing is
that while the code is able to search out the strings correctly, it doesn't
replace the text. The $line var loses its value for no reason.

I check for the occurrence of the search string
        if($pos=strpos ($line, $strfrom))

but when within the if block I try to echo $line I don't get the value, so
str_replace doesn't work either.

everything else works fine, the strangest thing is that I tried echoing the
$line value before the if block and it doesn't print anything, but it works
for the if condition.

I am getting the no of files and the line nos, where the search string
occurs, but no replacements happening. This is the replacement code:

                                        $newline=str_replace ($strfrom,
                                        echo "<br>New Line $newline";
                                                echo "<br>writable:";

Am I missing something really obvious here?


Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
Version: 6.0.370 / Virus Database: 205 - Release Date: 06/05/2002

PHP General Mailing List (
To unsubscribe, visit:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to