开发者

preg_replace doubt

开发者 https://www.devze.com 2023-04-07 10:52 出处:网络
What I\'m doing wrong ? echo preg_开发者_Go百科replace(\'#\\d{3}\\d{3}\\d{3}\\d{2}#\', \'$1.$2.$3-$4\', \'12345678901\');

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

精彩评论

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