php – preg_replace:在反向引用后添加数字

栏目: PHP · 发布时间: 7年前

内容简介:翻译自: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:在反向引用后添加数字》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。

Numerical Linear Algebra

Numerical Linear Algebra

Lloyd N. Trefethen、David Bau III / SIAM: Society for Industrial and Applied Mathematics / 1997-06-01 / USD 61.00

Numerical Linear Algebra is a concise, insightful, and elegant introduction to the field of numerical linear algebra.一起来看看 《Numerical Linear Algebra》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器