在PHP中创建活动链接


Making an active link in PHP

我用php创建了一个博客网站。这里有一个你可以发表评论的部分。当有人在评论中发布url时,我想知道如何才能使其处于活动状态。我注意到,当我在评论中使用url时,链接不是活动的,或者你不能将鼠标悬停在它上面。有没有代码可以使它处于活动状态?

您需要将字符串的URL部分转换为链接。

// The Regular Expression filter
$reg_exUrl = "/(http|https|ftp|ftps)':'/'/[a-zA-Z0-9'-'.]+'.[a-zA-Z]{2,3}('/'S*)?/";
// The Text you want to filter for urls
$text = "The text you want to filter goes here. http://google.com";
// Check if there is a url in the text
if(preg_match($reg_exUrl, $text, $url)) 
{
    // make the urls hyper links
    echo preg_replace($reg_exUrl, "<a href="{$url[0]}">{$url[0]}</a> ", $text);
} else {
    // if no urls in the text just return the text
    echo $text;
}

对于注释部分,而不是使用文本区域,请使用文本编辑器。市场上有很多开源文本编辑器。像

http://nicedit.com/===================this one very beautiful 
http://jhtmlarea.codeplex.com/
http://jqueryte.com/ 
http://ckeditor.com/