首页 > 编程 > PHP > 正文

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

2019-11-22 00:53:10
字体:
来源:转载
供稿:网友
复制代码 代码如下:

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;
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表