开发者

preg_replace doubt

What I'm doing wrong ?

echo preg_开发者_Go百科replace('#\d{3}\d{3}\d{3}\d{2}#', '$1.$2.$3-$4', '12345678901');

Output would be this: 123.456.789-01. Isn't formating the string!!


<?php
echo preg_replace('#(\d{3})(\d{3})(\d{3})(\d{2})#', '$1.$2.$3-$4', '12345678901');

is correct, because dollar sign + integer refers to content in () brackets (grouping)

demo


You have not grouped correctly (missing brackets):

echo preg_replace('#(\d{3})(\d{3})(\d{3})(\d{2})#', '$1.$2.$3-$4', '12345678901');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜