热门技术教程

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


次阅读 | 2011-09-05 | 标签:php | 网址 | 超链接 | 函数 |

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


上一篇:php中防止伪造跨站请求的小招式    下一篇:UTF-8 编码中BOM的检测与删除