[英]Yii: How can I linkify all URLs in some text?
Say I have a forum thread and I want to make all mentioned URLs as clickable links.假设我有一个论坛主题,我想将所有提到的 URL 作为可点击链接。 How can I accomplish this in Yii?
如何在 Yii 中完成此操作?
Thanks.谢谢。
This is copied straight from this stackoverflow question这是直接从这个stackoverflow问题复制的
$text = preg_replace("
#((http|https|ftp)://(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)#ie",
"'<a href=\"$1\" target=\"_blank\">$3</a>$4'",
$text
);
Did you look into CHtmlPurifier ?你调查过 CHtmlPurifier吗? see: Linkify and http://htmlpurifier.org/demo.php
请参阅: Linkify和http://htmlpurifier.org/demo.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.