如何替换文本URL并在HTML标签中排除URL?

我需要你的帮助。


我想转这个:


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

变成:


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

我已经通过使用此正则表达式来管理它:


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

问题在于它也在替换imgURL,例如:


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

变成:


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

请帮忙。


ITMISS
浏览 894回答 3
3回答
打开App,查看更多内容
随时随地看视频慕课网APP