21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
$url = 'http://api.map.baidu.com/place/v2/search?&query=%E9%93%B6%E8%A1%8C&location=39.915,116.404&radius=2000&output=json&ak=kvfo779F6gthGiGq4DFnOGHn';
$html = file_get_contents($url);
$json = json_decode($html, 1);
$d = array('name' => '', 'location' => '', 'address' => '');
foreach($json['results'] as $t) {
$res[] = array_intersect_key($t, $d);
}
function foo(&$v) { $v = urlencode($v); }
array_walk_recursive($res, 'foo');
$t = urldecode(json_encode($res));
file_put_contents('a1.txt', $t);
?>
<?php
$url = 'http://api.map.baidu.com/place/v2/search?&query=%E9%93%B6%E8%A1%8C&location=39.915,116.404&radius=2000&output=json&ak=kvfo779F6gthGiGq4DFnOGHn';
$html = file_get_contents($url);
$json = json_decode($html, 1);
$d = array('name' => '', 'location' => '', 'address' => '');
foreach($json['results'] as $t) {
$res[] = array_intersect_key($t, $d);
}
function foo(&$v) { $v = urlencode($v); }
array_walk_recursive($res, 'foo');
$t = urldecode(json_encode($res));
file_put_contents('a1.txt', $t);
?>
[/quote]
谢谢了啊!代码应该没问题了,我觉得我的文件设置的编码有问题!不过还是非常感谢你!function foo(&$v) { $v = urlencode($v); }
array_walk_recursive($res, 'foo');
$t = urldecode(json_encode($res));
file_put_contents('a1.txt', $t);
$url = 'http://api.map.baidu.com/place/v2/search?&query=%E9%93%B6%E8%A1%8C&location=39.915,116.404&radius=2000&output=json&ak=kvfo779F6gthGiGq4DFnOGHn';
$html = file_get_contents($url);
$json = json_decode($html, 1);
$d = array('name' => '', 'location' => '', 'address' => '');
foreach($json['results'] as $t) {
$res[] = array_intersect_key($t, $d);
}
file_put_contents('a1.txt', json_encode($res));
function foo(&$v) { $v = urlencode($v); }
array_walk_recursive($res, 'foo');
echo urldecode(json_encode($res));