views:

23

answers:

1

I'm trying to convert URLs, but not if they come after src=". So far, I have this...

return preg_replace('@(?!^src=")(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.-]*(\?\S+)?)?)?)@', '<a href="$1" target="_blank">$1</a>', $s);

It converts the URL, but even if it is before src="

+2  A: 

Make that a lookbehind assertion.

(?<!^src=")
John Kugelman
So simple, thanks!
Chris