Home > Backend Development > PHP Tutorial > 请问关于preg_replace替换的有关问题

请问关于preg_replace替换的有关问题

WBOY
Release: 2016-06-13 12:38:55
Original
1164 people have browsed it

请教关于preg_replace替换的问题
字符串  $str = 'aa__cc__ee';
企图使用这样的语句:  preg_replace('/_{2}?/', array('bb', 'dd'), $str);
替换成  'aabbccddee'
但全部换成了bb,我已经在表达式中加了 ? 号表示非贪婪,希望第一次匹配替换完之后不要再把第二个 __ 双下划线替换了,但发现这样不成功,请问怎么办才好?是不是我对贪婪模式理解错误了呢?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template