读书人

php 正则表达式报错

发布时间: 2012-05-12 15:39:31 作者: rapoo

php 正则表达式报错,高手请进。
$str = preg_replace("/(?<!\"[^>]*)(茶叶)(?!\"|<\/a>)/sui", '<a href="555.html">茶叶</a>', $str, 5);

报错如下:
Warning: preg_replace() [function.preg-replace]: Compilation failed: lookbehind assertion is not fixed length at offset 10 in D:\AppServ\www\Template\test.php on line 28


[解决办法]
试试

PHP code
        $html = <<<html这儿是茶叶的链接。<img src="中国好茶叶.jpg" width="120" height="120" alt="中国好茶叶" /><span title="中国好茶叶">中国茶叶</span>这儿是中国茶叶大观的链接。这儿是<a href="原有的链接.html">茶叶</a>的现有链接html;        echo preg_replace('#(?=[^>]*(?=<(?!/a>)|$))茶叶#','<a href="新加的链接.html">\0</a>',$html);    } 

读书人网 >PHP

热点推荐