我的数据返回如下:
2015-07-2111
ali,21,malaysia
alan,23,england
我预期的数组:
0=>2015-07-2111
1=>ali,21,malaysia
2=>alan,23,england
我的代码:
$info = explode(",",$string);
但代码不会产生我想要的数组。
答案 0 :(得分:1)
当你应该逐行拆分时,你将它,
拆分,所以改变
$info = explode(",", $string);
//where $info becomes an array of "ali", "21", "malaysia\nalan", "23", "england"
到
$info = explode(PHP_EOL, $string);
//where $info becomes an array of "ali,21,malaysia", "alan,23,england"
答案 1 :(得分:0)
您可以使用
$str = "2015-07-2111
ali,21,malaysia
alan,23,england";
echo '<pre>';
print_r(explode("\n",$str));