dosro793520628
dosro793520628
2015-04-08 10:37

带有短划线和数字的PHP preg_replace电话号码

  • php

I have a couple of phonenumbers listed in my database with a certain way of writing.
I want to have a space after every two numbers. I thought I would do:

$numbers = '06-12345678';
$regex = '/(\\d{2})(\\d{1})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/';
$result = preg_replace($regex, '$1 $2 $3 $4 $5 $6', $numbers);
echo $result;

But this doesn't work. It just places all the numbers next to each other.

My Expected Output:

06 - 12 34 56 78
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答