php中将网址转换为超链接的函数
发布时间:2016-12-29 来源:查字典编辑
摘要:复制代码代码如下:functionshowtext($text){$search=array('|(http://[^]+)|','|(ht...
复制代码 代码如下:
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;
}