正则表达式匹配URL——给URL地址加上<a> 链接

时间:2014-05-12 07:17:12   收藏:0   阅读:316
<?php
function replace_url ($content) {
	if (empty($content)) return;

	//给URL地址加上 <a> 链接
	$preg = ‘/(?:http:\/\/)?([\w.]+[\w\/]*\.[\w.]+[\w\/]*\??[\w=\&\+\%]*)/is‘;
	$content = preg_replace($preg, ‘<a href="http://\1" target="_blank">\1</a>‘, $content);

	return $content;
}

echo replace_url(‘百度:http://blog.csdn.net/moqiang02‘);
?>

正则表达式匹配URL——给URL地址加上<a> 链接,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!