Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


how to replace text urls and exclude urls in html tags


how to replace text urls and exclude urls in html tags  using -'php,html,regex,url'

I need you help here.

I want to turn this:

sometext sometext http://www.somedomain.com/index.html sometext sometext


into:

sometext sometext <a href="http://somedoamai.com/index.html">www.somedomain.com/index.html</a> sometext sometext


I have managed it by using this regex:

preg_replace("#((http|https|ftp)://(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)#ie", "'<a href=\"$1\" target=\"_blank\">$1</a>$4'", $text);


The problem is it’s also replacing the the img URL, for example:

sometext sometext <img src="http//domain.com/image.jpg"> sometext sometext


is turned into:

sometext sometext <img src="<a href="http//domain.com/image.jpg">domain.com/image.jpg</a>"> sometext sometext


Please help.
    

asked Sep 14, 2015 by HVIDevinyezb
0 votes
71 views



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...