我获得了这段代码来查找字符串中看起来像链接的文本,并将它们转换为a标记链接。因为我也使用tiny mce来输入数据,所以这种情况经常发生(因为tiny mce和其他编辑器喜欢段落)。
字符串
http://www.google.se</ p>脚本将生成以下链接
href=" http://www.google.se</ p>"(..hmm仅发现堆栈溢出文本以链接脚本作品:)
代码
$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以停止链接?
再加上一些更好的文本链接脚本的提示。那么stackoverflow texteditor是从哪里来的呢?
谢谢!
发布于 2011-08-26 20:13:38
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/[^\s<]*)?/";试试这个吧。将\S替换为^\s<
https://stackoverflow.com/questions/7204372
复制相似问题