-2

我正在尝试将以下字符串解析为数组。

$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] )

但我需要“维多利亚站,巴士站站”作为数组中的一项。我知道这可以通过正则表达式来实现。但我对此并不陌生。您的指导将不胜感激。

4

1 回答 1

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
于 2012-10-20T12:49:41.687 回答