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" Quote 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. Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.