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
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php