繁体   English   中英

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刚刚发现了stackoverflows文本来链接脚本作品:))

$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);

    }

找到<时,如何更改预浸料以停止链接?

也许还有关于更好的文本链接脚本的技巧。 实际上stackoverflows texteditor是从哪里来的?

谢谢!

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

试试这个。 用[^ \\ s <]替换\\ S

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM