Jump to content

Preg_replace with quote exceptions


jackr1909

Recommended Posts

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

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.