explode()一个字符串。脱掉白色空间

时间:2013-11-12 20:54:29

标签: php arrays string explode

我需要像这样爆炸$ k

$kExploded = explode(" ", $k);

现在,如果它有用,我也加上

var_dump($k)= string(20) "2013-01-01 12:00:00 " string(20) "2013-01-02 12:00:00 " 
               string(20) "2013-01-03 12:00:00 " 

如何爆炸$ K?

如果我回显$ k返回此

2013-01-01 12:00:00 2013-01-02 12:00:00 2013-01-03 12:00:00

我只是希望得到这个:

2013-01-0112:00:002013-01-0212:00:002013-01-0312:00:00//take off all white space

2 个答案:

答案 0 :(得分:0)

为什么不使用str_replace删除所有空格?

$k = "2013-01-01 12:00:00 2013-01-02 12:00:00 2013-01-03 12:00:00";
$k = str_replace(" ","",$k); // Replace white space, with no space in $k
echo $k; // 2013-01-0112:00:002013-01-0212:00:002013-01-0312:00:00

答案 1 :(得分:0)

在Stackoverflow上已经多次回答过,也许你应该先研究一下,但这应该可以解决问题:

preg_replace('/\s+/', '', $k);

已经回答了

How to strip all spaces out of a string in php?

Remove excess whitespace from within a string

也许还有更多地方......