jackr1909 Posted August 19, 2012 Share Posted August 19, 2012 Hi, I have a function that converts URL's in a string to links: $return = preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '<a href="$1" target="_blank">$1</a>', $return); Can i have some help amending it to exclude any links that are in quotes. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/267296-preg_replace-with-quote-exceptions/ Share on other sites More sharing options...
jazzman1 Posted August 19, 2012 Share Posted August 19, 2012 The easiest way is to use RegEx to exclude any links that are in quotes. Quote Link to comment https://forums.phpfreaks.com/topic/267296-preg_replace-with-quote-exceptions/#findComment-1370610 Share on other sites More sharing options...
jackr1909 Posted August 19, 2012 Author Share Posted August 19, 2012 How would i apply that? Quote Link to comment https://forums.phpfreaks.com/topic/267296-preg_replace-with-quote-exceptions/#findComment-1370624 Share on other sites More sharing options...
Psycho Posted August 19, 2012 Share Posted August 19, 2012 Try putting a negated quote match just before the http" $return = preg_replace('@[^"\'](https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '<a href="$1" target="_blank">$1</a>', $return); Quote Link to comment https://forums.phpfreaks.com/topic/267296-preg_replace-with-quote-exceptions/#findComment-1370626 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.