我想用一个空格分隔数字,数量为4。 1234567890,将成为1234 5678 90
我设法创建了一个脚本来实现这一目标,但它似乎超越了顶部,是否有更简单的方法来实现这一目标?
$num = 23853267362365;
$count = strlen($num)/4;
$new_num = array();
for ($x = 1; $x <= $count; $x++) {
$num_len = strlen($num);
if($num_len>4) {
$new_num[] = substr($num,0,4);
$num = substr($num,4,$num_len-4);
}
}
$num = implode(' ',$new_num);
答案 0 :(得分:3)
<span class="wrap"><input type="text">.pdf</span>
:
chunk_split()
答案 1 :(得分:0)
非chunk_split()
答案;不如Jessie Jackson的答案好,但适应任何长度。
$start_num = 23853267362365;
$chunk_length = 4; // change to whatever length you need
$count = ceil(strlen($num) / $chunk_length);
$concat =''; // initiate
for ($x = 0; $x < $count; $x++) {
$concat .= substr($start_num, ($chunk_length * $x), $chunk_length) . ' ';
}
$new_num = rtrim($concat, ' ');