livethedead Posted February 12, 2012 Share Posted February 12, 2012 I'm learning PHP as my first language so bear with me. I seriously cannot figure out how to escape the (/) in this regex for a url. $facebook = preg_replace("/facebook.org/\|facebook.net/\/i", "/facebook.com/\/i", trim($_REQUEST['facebook_url'])); Warning: preg_replace() [function.preg-replace]: Unknown modifier '\' edit: Sorry I thought I posted this in the regex forum. Quote Link to comment https://forums.phpfreaks.com/topic/256967-simple-escaping-in-regex/ Share on other sites More sharing options...
GingerRobot Posted February 12, 2012 Share Posted February 12, 2012 You should place the backslash (\) before the character you wish to escape. Quote Link to comment https://forums.phpfreaks.com/topic/256967-simple-escaping-in-regex/#findComment-1317334 Share on other sites More sharing options...
livethedead Posted February 12, 2012 Author Share Posted February 12, 2012 Ahhh thanks. Quote Link to comment https://forums.phpfreaks.com/topic/256967-simple-escaping-in-regex/#findComment-1317345 Share on other sites More sharing options...
AyKay47 Posted February 13, 2012 Share Posted February 13, 2012 Ahhh thanks. I like to use other characters as delimiters, like the "~" so I do not have to escape forward slashes. Quote Link to comment https://forums.phpfreaks.com/topic/256967-simple-escaping-in-regex/#findComment-1317395 Share on other sites More sharing options...
livethedead Posted February 13, 2012 Author Share Posted February 13, 2012 Thank you very much, wasn't aware I could do that. Quote Link to comment https://forums.phpfreaks.com/topic/256967-simple-escaping-in-regex/#findComment-1317403 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.