Home  >  Article  >  Backend Development  >  哪位高手能帮忙写一个正则表达式

哪位高手能帮忙写一个正则表达式

WBOY
WBOYOriginal
2016-06-13 10:05:23742browse

谁能帮忙写一个正则表达式
url替换为超连接

比如:
呵呵http://www.sina.com.cn西西哈哈    
替换之后是:
呵呵 http://www.sina.com.cn 西西哈哈

在比如:
中国最大的技术论坛:www.csdn.net,你可以学到很多东西
替换之后是:
中国最大的技术论坛: www.csdn.net ,你可以学到很多东西

总之,是URL都要替换为超连接.高手帮忙写一下.谢谢

------解决方案--------------------


function enable_url($str)
{
$str = ereg_replace( "([url]www.[a-zA-Z0-9@:%_.~#-\?&]+[/url]) ", " \\1 ", $str); // 自动转化www开头的链接
$str = ereg_replace( "(((f|ht){1}tp://)[a-zA-Z0-9@:%_.~#-\?&]+) ", " \\1 ", $str); //转化[url]http://开头和ftp://开头的链接[/url]
$str = str_replace( 'linkHttp:// ', 'http:// ',$str);
$str = ereg_replace( "([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}) ", " \\1 ", $str); // 转化邮件地址
return $str;
}
//for example
echo enable_url( "呵呵http://www.sina.com.cn西西哈哈 ");

?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn