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); ?> 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 = '/_/'; 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. 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
Archived
This topic is now archived and is closed to further replies.