首页 > 开发 > PHP > 正文

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

2024-05-04 22:06:26
字体:
来源:转载
供稿:网友
代码如下:
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;
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表