-1

我希望使用 preg_split 像电话号码一样显示一个数字:

$number = '1234567890';
// preg_split
$number = '123 456 7890';

例如也许:

implode(' ', preg_split('/pattern/', $number))
4

2 回答 2

4
$number = '1234567890';
$number = preg_replace('/(\d{3})(\d{3})(\d{4})/','$1 $2 $3',$number);
于 2013-01-18T10:06:31.153 回答
0

试试这个-

$str = "1234567890";
$split = str_split($str, 3);
echo $split[0]." ".$split[1]." ".$split[2].$split[3];

或者

     $number= "1234567890";
    echo substr($number,0,3)." ".substr($number,3,3)." ".substr($number,5);
于 2013-01-18T10:05:54.003 回答