欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-11-15 13:29:40
复制代码 代码如下: function showtext($text){ $search = array('|(http://[^ ]+)|', '|(https://[^...
复制代码 代码如下:

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;
}