$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
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
解决方案 »
- PHP5 安装问题
- 我程序设置是UTF8编码,可是页面显示全是问号?
- 为什么isset($_GET['a'])可以用,isset($_POST['a'])就不可用呢。
- 紧急求助:各位大虾,这段cookie的登录注销代码,哪里错了??
- 小段ASP转PHP
- 请问一下在一些网站当中二级分类是怎么实现的,谢谢
- $_SERVER['DOCUMENT_ROOT']和basename(__FILE__)的路径不一致,使程序包含路径问题出错了,请问这是怎么回事啊?
- phpMyAdmin为什么连不上?
- 如何实现图文混排?
- 有支持PHP的 免费空间吗?
- ajax预加载页面的问题。
- PHP页面表单处理函数和表单在一个页面上好吗?
原字符串内容:这儿是茶叶的链接。
<img src="中国好茶叶.jpg" width="120" height="120" alt="中国好茶叶" />
<span title="中国好茶叶">中国茶叶</span>
这儿是中国茶叶大观的链接。
这儿是<a href="原有的链接.html">茶叶</a>的现有链接。要实现的效果:这儿是<a href="新加的链接.html">茶叶</a>的链接。
<img src="中国好茶叶.jpg" width="120" height="120" alt="中国好茶叶" />
<span title="中国好茶叶">中国<a href="新加的链接.html">茶叶</a></span>
这儿是中国<a href="新加的链接.html">茶叶</a>大观的链接。
这儿是<a href="原有的链接.html">茶叶</a>的现有链接。
接着直接str_replace('茶叶', '<a href="新加的链接.html">茶叶</a>', $str)。
最后恢复$save的数据。当然能一次正则能搞定最好拉。。不过应该不好写。正则达人上吧
$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不是不支持?<这样的零宽,而是后边必须跟着固定宽度的正则串,所以爆了is not fixed length的错误,意思是?<!后的正则串不能有*,+,{1,}等等不固定宽度的正则串。