我在 php 中有一个如下所示的 $line
33 0 0 51037280 396822 15 16 0 0 0 0 20907 143197 57377 27 12 51 10 7.33 45.8 17:07:31
我尝试创建和排列并将每个由空格分隔的值放到这个数组中,如下所示:
$parts=explode(" ", $line)
应该有 20 个索引,这条 $line 上有 21 个列。但是当我这样做时:
$size=sizeof($parts)
echo $size 返回 58,这怎么可能。有没有更好的方法将 $line 中的项目插入到数组中?看起来值之间有不规则数量的空格。当我这样做时:
print_r($parts)
我得到以下信息:
[0] => [1] => 33 [2] => [3] => [4] => 0 [5] => [6] => [7] => 0 [8] => [9] => [10] => 51037280 [11] => [12] => [13] => [14] => [15] => 396822 [16] => [17] => [18] => [19] => 15 [20] => [21] => [22] => [23] => 16 [24] => [25] => [26] => [27] => [28] => 0 [29] => [30] => [31] => [32] => [33] => 0 [34] => [35] => [36] => [37] => [38] => 0 [39] => [40] => [41] => [42] => [43] => [44] => 0 [45] => 20907 [46] => 143197 [47] => 57377 [48] => 27 [49] => 12 [50] => 51 [51] => 10 [52] => [53] => 7.33 [54] => [55] => 45.8 [56] => 17:07:31 )
我将如何忽略值之间的空格数并将每个值作为数组值存储在 php 中?