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