0
可能重复:
Replace URLs in text with HTML linksPHP转换所有URL转换成HTML链接
我传递包含多个URL字符串变量,通过下面的函数来获得同样的事情,只有正确HTML链接。
public function convertUrlsToLinks($text){
return preg_replace('@(?<![.*">])\b(?:(?:https?|ftp|file)://|[a-z]\.)[-A-Z0-9+&#/%=~_|$?!:,.]*[A-Z0-9+&#/%=~_|$]@i', '<a href="\0" target="_blank">\0</a>', $text);
}
它根本不起作用。我错过了什么?
代码必须跳过现有的联系,<img>
的src
值(或类似的东西。)