Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中创建活动链接_Php - Fatal编程技术网

在PHP中创建活动链接

在PHP中创建活动链接,php,Php,我用php创建了一个博客网站。有一部分你可以发表评论。我想知道当有人在评论中发布一个url时,我如何才能激活该url。我注意到,当我在评论中添加url时,链接不处于活动状态,或者你不能将鼠标悬停在上面。是否有代码将其激活?您需要将字符串的URL部分转换为链接 // The Regular Expression filter $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; /

我用php创建了一个博客网站。有一部分你可以发表评论。我想知道当有人在评论中发布一个url时,我如何才能激活该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;
}
//正则表达式筛选器
$reg|u exUrl=“/(http | https | ftp | ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/”;
//要筛选URL的文本
$text=“要筛选的文本位于此处。http://google.com";
//检查文本中是否有url
if(preg_match($reg_exUrl,$text,$url))
{
//使URL成为超链接
echo preg_替换($reg_exUrl,“,$text);
}否则{
//如果文本中没有URL,请返回文本
echo$文本;
}

您需要将字符串的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;
}
//正则表达式筛选器
$reg|u exUrl=“/(http | https | ftp | ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/”;
//要筛选URL的文本
$text=“要筛选的文本位于此处。http://google.com";
//检查文本中是否有url
if(preg_match($reg_exUrl,$text,$url))
{
//使URL成为超链接
echo preg_替换($reg_exUrl,“,$text);
}否则{
//如果文本中没有URL,请返回文本
echo$文本;
}

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

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

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

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

非常感谢。我会试试。正面反馈会很好:)明天早上我会试试。变量$url的值是多少?只是好奇。以防万一我出了差错。这很有效。非常感谢你。还有其他方面我可以留下正面反馈吗?谢谢。我会试试。正面反馈会很好:)明天早上我会试试。变量$url的值是多少?只是好奇。以防万一我出了差错。这很有效。非常感谢你。还有其他我可以留下正面反馈的地方吗?很有趣。我正在为管理部分使用文本编辑器。从未想过将其添加到评论部分。谢谢,很有趣。我正在为管理部分使用文本编辑器。从未想过将其添加到评论部分。谢谢