roughie Posted February 19, 2008 Share Posted February 19, 2008 One of the two strings being replaced, "takes", whereas the other doesn't! But WHY? file1: test.php <?php $yyy = "abcde"; $zzz = "hijkl"; $tmp = @file_get_contents("test.tpl"); $tmp = str_replace(array("%%xxx%%%", "%%www%%"), array($yyy, $zzz), $tmp); echo $tmp; ?> file1: test.tpl <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><title>tst replace</title></head> <body> <div> <label> Value 1: </label> <input type="text" name="listid" size="10" value="%%xxx%%" /> <br /> <label> Value 2: </label> <input type="text" name="listid" size="10" value="%%www%%" /> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/91905-whats-wrong-with-this-str_replace/ Share on other sites More sharing options...
marcus Posted February 19, 2008 Share Posted February 19, 2008 <?php $string = <<< EOD <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><title>tst replace</title></head> <body> <div> <label> Value 1: </label> <input type="text" name="listid" size="10" value="%%xxx%%" /> <label> Value 2: </label> <input type="text" name="listid" size="10" value="%%www%%" /> </div> </body> </html> EOD; $yyy = "abcde"; $zzz = "hijkl"; $tmp = str_replace(array("%%xxx%%", "%%www%%"), array($yyy, $zzz), $string); echo $tmp; ?> You have an extra percentage sign on the "%%xxx%%" Link to comment https://forums.phpfreaks.com/topic/91905-whats-wrong-with-this-str_replace/#findComment-470610 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.