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

<?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');
?>

原文地址:https://www.cnblogs.com/moqiang02/p/4061322.html