preg_replace('/\{[a-zA-Z.,\(\)0-9]+\}/', 'Replaced', 'Lorem ipsum dolor sit {tag1({tag2()})}, consectetur adipiscing elit.');
其结果是:
Lorem存有悲坐{TAG1(代替)},consectetur adipiscing ELIT。
问题
正如你可以看到“标签2”已经被替换,但我想替换“标签1” 难道有谁知道我能做到这一点?
(在某些情况下,它可能是这样的:{tag1({tag2({tag3()})})})
等)
顺便说一句,我实际使用preg_replace_callback,但它更容易preg_replace
这里来显示它是一个网站,你可以测试代码:http://www.spaweditor.com/scripts/regex/index.php
什么'something.something'和'在你的榜样print.print'之间的区别? – kennytm 2010-04-28 08:03:18
通过“替换一切,但:something.something'”你的意思是,给定示例文本,从'preg_replace'返回的字符串应该是'something.something' ...或者你想要替换*大括号中的所有内容*与*第一个'something.something'风格值*? – salathe 2010-04-28 08:20:13
结果应该是something.something其他所有的东西都必须被替换。 – christian 2010-04-28 17:23:38