如何从url位置获取数据

时间:2011-04-21 07:00:50

标签: php json

我正在使用JSON,我必须在其中获取特定城市的位置,例如:http://maps.google.com/maps/geo?q=Vanguard,CA,%20United%20States&output=json

现在在PHP中如何编写代码来获取“Point”数据?

3 个答案:

答案 0 :(得分:3)

只要php.ini中有allow_url_fopen,您就可以使用file_get_contents()。然后,您可以使用json_decode()进行解析。

$json = json_decode(file_get_contents('http://maps.google.com/maps/geo?q=Vanguard,CA,%20United%20States&output=json'), TRUE);

$json现在是您的JSON数据数组。

答案 1 :(得分:1)

$json_data=file_get_contents($url);
在这种情况下,

allow_url_fopen应为on

Curl可用作备用选项

答案 2 :(得分:1)

我建议使用cURL lib。 (cUrL)。它提供了更多选项和错误处理,然后使用file_get_contents等替代方案。

相关问题