我想用 preg_replace()
在数字集之间添加空格;
$numbers = '90000800123987';
期望的输出:900 00 800 123 987
此时我很困惑,到目前为止我无法获得所需的输出。
最佳答案
对于您的具体示例,可以这样做:
$numbers = '90000800123987';
$regex = '/(\\d{3})(\\d{2})(\\d{3})(\\d{3})(\\d{3})/';
$result = preg_replace($regex, '$1 $2 $3 $4 $5', $numbers);
关于php - 在数字字符串的特定位置添加空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10299432/