$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);
// $txt=file($html);
echo $html;
file_put_contents('a1.txt',$html);
?>
我现在只能输出全部的信息到本地txt中!就是不明白怎么判断输出那3个信息到本地txt中!求指导
$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));
$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));
大神,非常感谢你!但是为什么我输出的是一堆乱码饿了?[{"name":"\u4e2d\u56fd\u5de5\u5546\u94f6\u884c(\u548c\u5e73\u95e8\u5185\u652f\u884c)","location":{"lat":39.90742,"lng":116.390732},"address":"\u5317\u4eac\u5e02\u897f\u57ce\u533a\u5317\u65b0\u534e\u8857\u4e1c\u677e\u6811\u80e1\u540c\u753231\u53f7"},{"name":"\u4e2d\u56fd\u5de5\u5546\u94f6\u884c(\u4e1c\u4ea4\u6c11\u5df7\u50a8\u84c4\u6240)","location"。。。。。
$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));
处理一下
function foo(&$v) { $v = urlencode($v); }array_walk_recursive($res, 'foo');echo urldecode(json_encode($res));
你保存的不是 echo 的结果吗?
function foo(&$v) { $v = urlencode($v); }array_walk_recursive($res, 'foo');$t = urldecode(json_encode($res));file_put_contents('a1.txt', $t);
你保存的不是 echo 的结果吗?
function foo(&$v) { $v = urlencode($v); }array_walk_recursive($res, 'foo');$t = urldecode(json_encode($res));file_put_contents('a1.txt', json_encode($t));
你保存的不是 echo 的结果吗?
function foo(&$v) { $v = urlencode($v); }array_walk_recursive($res, 'foo');$t = urldecode(json_encode($res));file_put_contents('a1.txt', json_encode($t));
'', '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);?>
你保存的不是 echo 的结果吗?
function foo(&$v) { $v = urlencode($v); }array_walk_recursive($res, 'foo');$t = urldecode(json_encode($res));file_put_contents('a1.txt', json_encode($t));
'', '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);?>