0
Basicaly,我发现了一些代码在这里:PHP不完全linkifying
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:[email protected]$3\">[email protected]$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;
很抱歉,如果我不能更详细一些,但我不知道如何在这一刻来解决这个时间。
在正则表达式,你会看到.. \ n \ r \ t < .... <应该是一个<。它看起来像你复制的HTML源代码,它改变<< – kainaw
你也可以在你使用的例子中没有正确编码html,只是将它改为'<'。 – Flosculus