dreamwest Posted November 23, 2008 Share Posted November 23, 2008 why does this str_replace not work? <?php $config = "this is the message"; $ch = str_replace("{config}",$config,$ch); ?> <?php echo $ch; ?> it should show "this is the message" Link to comment https://forums.phpfreaks.com/topic/133887-why-does-this-str_replace-not-work/ Share on other sites More sharing options...
Mark Baker Posted November 23, 2008 Share Posted November 23, 2008 why does this str_replace not work? it should show "this is the message" $ch isn't being initialised, so it certainly can't contain "{config}", hence nothing gets replaced. Link to comment https://forums.phpfreaks.com/topic/133887-why-does-this-str_replace-not-work/#findComment-696938 Share on other sites More sharing options...
blufish Posted November 23, 2008 Share Posted November 23, 2008 Try this... <?php $config = "this is the message"; $ch = "bla bla {config}" $ch = str_replace("{config}",$config,$ch); ?> <?php echo $ch; ?> You must already have something in the $ch variable before you can replace things in it. Link to comment https://forums.phpfreaks.com/topic/133887-why-does-this-str_replace-not-work/#findComment-696963 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.