I'm trying to convert plain links to HTML links using preg_replace. However it's replacing links that are already converted.
To combat this I'd like it to ignore the replacement if the link starts with a quote.
I think a positive lookahead may be needed but everything I've tried hasn't worked.
$string = '<a href="http://www.example.com">test</a> http://www.example.com';
$string = preg_replace("/((https?:\/\/[\w]+[^ \,\"\n\r\t<]*))/is", "<a href=\"$1\">$1</a>", $string);
var_dump($string);
The above outputs:
<a href="<a href="http://www.example.com">http://www.example.com</a>">test</a> <a href="http://www.example.com">http://www.example.com</a>
When it should output:
<a href="http://www.example.com">test</a> <a href="http://www.example.com">http://www.example.com</a>