内容简介:翻译自:https://stackoverflow.com/questions/18027811/preg-replace-add-number-after-backreference
情况
我想使用preg_replace()在每个[aeiou]之后添加一个数字’8′.
例
从
abcdefghij
至
a8bcde8fghi8j
题
我该如何写替换字符串?
// input string $in = 'abcdefghij'; // this obviously won't work ----------↓ $out = preg_replace( '/([aeiou])/', '\18', $in);
这只是一个示例,因此建议str_replace()不是有效的答案.
我想知道如何在替换字符串中的反向引用后有数字.
解决方案是将反向引用包装在${}中.
$out = preg_replace( '/([aeiou])/', '${1}8', $in);
这将输出a8bcde8fghi8j
有关此反馈的特殊情况,请参见 the manual .
翻译自:https://stackoverflow.com/questions/18027811/preg-replace-add-number-after-backreference
以上所述就是小编给大家介绍的《php – preg_replace:在反向引用后添加数字》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 强引用、软引用、弱引用、虚引用
- java的强引用、软引用、弱引用、幻象引用,引用队列总结
- Java 对象引用方式 —— 强引用、软引用、弱引用和虚引用
- 强引用、软引用、弱引用、幻象引用有什么区别?
- 你确定真的了解 Java 四种引用(强引用、弱引用、软引用、虚引用)了吗?
- java:强引用,软引用,弱引用和虚引用
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Art of Computer Programming, Volumes 1-3 Boxed Set
Donald E. Knuth / Addison-Wesley Professional / 1998-10-15 / USD 199.99
This multivolume work is widely recognized as the definitive description of classical computer science. The first three volumes have for decades been an invaluable resource in programming theory and p......一起来看看 《The Art of Computer Programming, Volumes 1-3 Boxed Set》 这本书的介绍吧!