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');
精彩评论