基本上,我在这里找到了一些代码:
http://buildinternet.com/2010/05/how-to-automatically-linkify-text-with-php-regular-expressions/
自动将文本链接转换为可点击链接。
但是有一个我无法发现的错误,因为我对正则表达式并不是很好,因为它没有完全捕获文本或类似的东西。如下所示:
代码:
function link_filter_offence($player_complaints_offence_raw)
{
$player_complaints_offence_raw= preg_replace("/(^|[\n ])([\w]*?)((ht|f)tp(s)?:\/\/[\w]+[^ \,\"\n\r\t<]*)/is", "$1$2<a href=\"$3\" >$3</a>", $player_complaints_offence_raw);
$player_complaints_offence_raw= preg_replace("/(^|[\n ])([\w]*?)((www|ftp)\.[^ \,\"\t\n\r<]*)/is", "$1$2<a href=\"http://$3\" >$3</a>", $player_complaints_offence_raw);
$player_complaints_offence_raw= preg_replace("/(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+)+)/i", "$1<a href=\"mailto:$2@$3\">$2@$3</a>", $player_complaints_offence_raw);
return($player_complaints_offence_raw);
}
$player_complaints_offence_raw = 'https://www.youtube.com/watch?v=klXTQjmfVeg&feature=youtu.be';
$player_complaints_offence_raw = link_filter_offence($player_complaints_offence_raw);
$reply = html_entity_decode($player_complaints_offence_raw);
echo $reply;
很抱歉,如果我不能更详细,但我不知道如何解决这个问题。
答案 0 :(得分:0)
试试这个
{2,}
我所做的就是我已经逃脱了preg_replace函数的第二个参数,它对我来说非常适合