简体   繁体   English

更改电话号码的格式

[英]Change format of phone number

I have string with phone number that I need to transform from one format to another. 我的电话号码字符串需要从一种格式转换为另一种格式。

Example: 例:

"02030266079" => "0203 026 6079"

I tried: 我试过了:

$num = "02030266079";
$transformed= preg_replace("/^(/d{4})(/d{3})(/d{4})$/", "$1 $2 $3", $num);

But nothing happens! 但是什么也没发生!

$number = "12345678901";
$formatted_number = preg_replace("/^(\d{4})(\d{3})(\d{4})$/", "$1 $2 $3", $number);

It is php code and well tested, It works perfectly 它是php代码,并且经过了良好的测试,可以完美地工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM