preg match thar在文本中找到链接,但在标记之前停止“<&”;


preg-match thar finds links in text but stop before tags "<"

我得到这段代码是为了在一个看起来像链接的字符串中找到文本,并将它们转换为a-tag链接。由于我也使用微小的mce来输入数据,这种情况经常发生(因为微小的mce和其他编辑喜欢段落(。

字符串

http://www.google.se</ p>

脚本生成链接

href=" http://www.google.se</ p>"

(..hmm刚刚发现stackoverflow文本链接脚本作品:(

代码

$reg_exUrl = "/(http|https|ftp|ftps)':'/'/[a-zA-Z0-9'-'.]+'.[a-zA-Z]{2,3}('/'S*)?/";
if(preg_match($reg_exUrl, $string, $url)) {

       return preg_replace($reg_exUrl, "<a href='"" . $url[0] . "'" target='"_blank'">" . $url[0] . "</a> ", $string);
    }

当发现<时,如何更改preg以停止链接?

再加上关于更好的文本链接脚本的提示。stackoverflows文本编辑器实际上是从哪里来的?

谢谢!

$reg_exUrl = "/(http|https|ftp|ftps)':'/'/[a-zA-Z0-9'-'.]+'.[a-zA-Z]{2,3}('/[^'s<]*)?/";

试试这个。将''S替换为[^''S<]