PHP reg expr. replace ALL URLs except img src URLs
- by zilveer
Hi,
I have searched but havent been able to find my answer.
It follows like:
I would like to replace all URL in a string to links except the URLs within img src tag.
I have a regular expression for replacing all the URLs to links, but would like it to NOT replace the URLs within img src="" attribute.
How can i do this?
Here is the code for replacing all URLs:
/*** make sure there is an http:// on all URLs ***/
$str = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2",$str);
/*** make all URLs links ***/
$str = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</a>",$str);
/Regards