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); ?> 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); ?> 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." 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. 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 Link to comment https://forums.phpfreaks.com/topic/74251-preg_replace-help/#findComment-375463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.