【发布时间】:2017-06-10 03:45:26
【问题描述】:
我想将此字符串转换为适当的关联数组。
请点击链接查看字符串数据。
https://maps.googleapis.com/maps/api/geocode/json?latlng=16.539311299999998,80.5820222
我希望将其转换为适当的关联数组。
我看起来像这样。
echo $array['long_name'] 应该返回一个类似'Attlee Road'的值
请帮我解决这个问题,我从 2 天开始尝试这个,尝试所有的爆炸、内爆、foreachloops,我很困惑,请有人帮我解决这个问题。
下面的代码会回显字符串数据
<?php
$lat = 16.539311299999998;
$lng = 80.5820222;
$url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" . $lat . "," . $lng . ";
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$returned_contents = get_data($url);
echo "<pre>";
print_r($returned_contents);
echo "</pre>";
?>
【问题讨论】:
标签: php arrays json string explode