Organizational Research By

Surprising Reserch 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
81 views



Related Hot Questions

7 Answers

0 votes
NULL
answered Sep 14, 2015 by SethRtgjokv
0 votes
NULL
answered Sep 14, 2015 by RussellReece
0 votes
NULL
answered Sep 14, 2015 by EarleneAguil
0 votes
NULL
answered Sep 14, 2015 by GildaProudl
0 votes
NULL
answered Sep 14, 2015 by NannieLillic
0 votes
NULL
answered Sep 14, 2015 by LorPleasant
0 votes
NULL
answered Sep 14, 2015 by MolBaddeley

...