我正在尝试将以下字符串解析为数组。
$str = [0,"Victoria Station, Bus Station Stand",null,null,0,null,51.496169,-0.143633]
我正在使用
$result = explode(',', $str);
我正在获得这样的数组
Array ( [0] => [0 [1] => "Victoria Station [2] => Bus Station Stand" [3] => null [4] => null [5] => 0 [6] => null [7] => 51.496169 [8] => -0.143633] )
但我需要“维多利亚站,巴士站站”作为阵列中的1项。我知道这可以用正则表达式来实现。但我是新手。非常感谢您的指导。
答案 0 :(得分:6)
对我来说这看起来像json
$str = '[0,"Victoria Station, Bus Station Stand",null,null,0,null,51.496169,-0.143633]';
$json = json_decode($str, true);
echo "<pre>";
var_dump($json);
输出
array
0 => int 0
1 => string 'Victoria Station, Bus Station Stand' (length=35)
2 => null
3 => null
4 => int 0
5 => null
6 => float 51.496169
7 => float -0.143633