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. :-)
-Natalie -----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, $strto,$line); echo "<br>New Line $newline"; if(is_writable($file)) { echo "<br>writable:"; if(fputs($fd,$newline)) $replaced_links++; } Am I missing something really obvious here? thanks. Naintara --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.370 / Virus Database: 205 - Release Date: 06/05/2002 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php