jaxdevil Posted June 21, 2008 Share Posted June 21, 2008 I am trying to replace the character underscore ( _ ) with a space. It is not working, it is making the whole string blank. Any thing I am doing wrong? <? $string = $row['subcat']; $replacement = ' '; $pattern = '_'; echo preg_replace($pattern, $replacement, $string); ?> Quote Link to comment https://forums.phpfreaks.com/topic/111280-preg-replace-problem-maybe-with-_/ Share on other sites More sharing options...
.josh Posted June 21, 2008 Share Posted June 21, 2008 $pattern = '/_/'; Quote Link to comment https://forums.phpfreaks.com/topic/111280-preg-replace-problem-maybe-with-_/#findComment-571205 Share on other sites More sharing options...
Bauer418 Posted June 21, 2008 Share Posted June 21, 2008 For something this simple I'd advise that you use str_replace rather than preg_replace. str_replace is much faster. Quote Link to comment https://forums.phpfreaks.com/topic/111280-preg-replace-problem-maybe-with-_/#findComment-571206 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.