php中将网址转换为超链接的函数

 更新时间:2011年09月02日 15:27:30   作者:  
php中将网址转换为超链接的函数,需要的朋友可以参考下。
复制代码 代码如下:

function showtext($text){
$search = array('|(http://[^ ]+)|', '|(https://[^ ]+)|', '|(www.[^ ]+)|');
$replace = array('<a href="$1" target="_blank">$1</a>', '<a href="$1" target="_blank">$1</a>', '<a href="http://$1" target="_blank">$1</a>');
$text = preg_replace($search, $replace, $text);
return $text;
}

相关文章

最新评论