lupld Posted October 21, 2007 Share Posted October 21, 2007 k, gotta be honest, I don't get the preg_replace syntax at all... and the more I look the worse it gets... I'm trying to replace quotations " with escape codes " <?php $patterns = '/"/'; $replacements = '"'; preg_replace($patterns, $replacements, $message); ?> Quote Link to comment https://forums.phpfreaks.com/topic/74251-preg_replace-help/ Share on other sites More sharing options...
trq Posted October 21, 2007 Share Posted October 21, 2007 Better off simply using str_replace for such simple replacements (its quite a bit quicker). <?php str_replace('"', """, $message); ?> Quote Link to comment https://forums.phpfreaks.com/topic/74251-preg_replace-help/#findComment-375095 Share on other sites More sharing options...
BlueSkyIS Posted October 21, 2007 Share Posted October 21, 2007 but when used, you need to assign to the function return value: <?php $message = 'Joe once said, "There is no way to replace double quotes."'; $patterns = '/"/'; $replacements = '"'; $message = preg_replace("$patterns", $replacements, $message); echo "message: $message \n"; ?> output: message: Joe once said, "There is no way to replace double quotes." Quote Link to comment https://forums.phpfreaks.com/topic/74251-preg_replace-help/#findComment-375101 Share on other sites More sharing options...
cooldude832 Posted October 22, 2007 Share Posted October 22, 2007 there are lots of regex patterns pre developed out there, if you need a specific pattern try googling it. Its not a normal pattern it follows its own language like ASCII kinda. Quote Link to comment https://forums.phpfreaks.com/topic/74251-preg_replace-help/#findComment-375120 Share on other sites More sharing options...
effigy Posted October 22, 2007 Share Posted October 22, 2007 htmlentities Quote Link to comment https://forums.phpfreaks.com/topic/74251-preg_replace-help/#findComment-375463 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.