Re: str_replace not replacing

From: Date: Wed, 11 Feb 2004 15:09:29 +0000
Subject: Re: str_replace not replacing
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-177400@lists.php.net to get a copy of this message
Aaron Merrick wrote:
I'm reading in to a variable $section1 an entire php file that creates a mysql table. I can output the variable in a new file just fine (figured out what all had to be escaped in the original file). My problem is, I want to replace the table name in the original file with a new table name before I output it to the new file. But the str_replace has no effect. Neither does an ereg_replace. Is there something in the content of the file that is foiling the replace? Here is what I have right now. It produces the same file content as is read in. <?php $search = "item"; $replace = "poem"; mkdir($replace, 0777); $section1 = file_get_contents("table_create.php"); str_replace($search, $replace, $section1); chdir($replace); $table_create = fopen($replace."_table_create.php","w+"); fwrite($table_create,$section1); ?>
str_replace() doesn't affect $section1; it returns the subject with the replacements, so you'd need: $section1 = str_replace($search, $replace, $section1); Of course, you'd know this if you had RTFM ;-) http://www.php.net/str_replace Mike

« previous php.general (#177400) next »