<?php
$link = 'https://s.index.baidu.com.cn:8080/index/word.php?word=%C6%A5%C5%E4%CD%F8%D6%B7&id=12&type=OVFb9igkeNY#pl10010';
$email = '[email protected]';
$test = "我们经常访问的网址是$link,我的email是$email";$url_reg = "/https?:\/\/([一-龥a-zA-Z\/\d\-]{1,30}\.){1,}([一-龥a-zA-Z]{2,9})(:\d{1,5})?([\/|\\]{1}[\w\.\?=%&#]+)*/u";
$test = preg_replace($url_reg,"<a href='\$0'>\$0</a>",$test);$email_reg = '/[[:alnum:]._-]+@[[:alnum:]-]+\.([[:alnum:]-]+\.)*[[:alnum:]]+/';
$test = preg_replace($email_reg,"<a href='mailto:\$0'>\$0</a>",$test);
echo $test;
?>
看看能用么?不行再改改正则表达式
我的结果是这样的:
我们经常访问的网址是<a href='https://s.index.baidu.com.cn:8080/index/word.php?word=%C6%A5%C5%E4%CD%F8%D6%B7&id=12&type=OVFb9igkeNY#pl10010'>https://s.index.baidu.com.cn:8080/index/word.php?word=%C6%A5%C5%E4%CD%F8%D6%B7&id=12&type=OVFb9igkeNY#pl10010</a>,我的email是<a href='mailto:[email protected]'>[email protected]</a>