日期:2014-05-17 浏览次数:20432 次
$s = 'baid,baidu,baidu,google,baidu <a href="http://www.baidu.com"> baidu </a> sdfsdf www.baidu.com '; echo preg_replace("/(?<!www\.)(baidu)(?!\.com)/","<b>\\1</b>",$s);
------解决方案--------------------
$search = array("/(.*)([^\.]baidu[^\.])(.*)/", "/(.*)([^\.]baid[^\.])(.*)/", "/(.*)([^\.]google[^\.])(.*)/");
$replace = "\$1<b> baidu </b>$3";
$str = '<a href="http://www.baidu.com.com" > baidu baid </a><a href="http://www.baidu.com.com" > 12312 google </a>';
$res = preg_replace( $search, $replace, $str );
exit($res);
------解决方案--------------------
貌似PHP里有反向预查,那样的话,很简单的就可以解决了...:D
飘走...