怎么实现只输出“name” “location” “address”到本地txt中 txturljson 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $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"。。 大神,非常感谢你!但是为什么我输出的是一堆乱码饿了?[{"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"。。 处理一下function foo(&$v) { $v = urlencode($v); }array_walk_recursive($res, 'foo');echo urldecode(json_encode($res)); 现在在网页的页面能正确显示了!但是在txt中还是乱码![{"name":"%E4%B8%AD%E5%9B%BD%E5%B7%A5%E5%95%86%E9%93%B6%E8%A1%8C%28%E5%92%8C%E5%B9%B3%E9%97%A8%E5%86%85%E6%94%AF%E8%A1%8C%29","location":{"lat":"39.90742","lng":"116.390732"},"address":"%E5%8C%97%E4%BA%AC%E5%B8%82%E8%A5%BF%E5%9F%8E%E5%8C%BA%E5%8C%97%E6%96%B0%E5%8D%8E%E8%A1%97%E4%B8%9C%E6%9D%BE%E6%A0%91%E8%83%A1%E5%90%8C%E7%94%B231%E5%8F%B7"},{"name":"%E4%B8%AD%E5%9B%BD%E5%B7%A5%E5%95%86%E9%93%B6%E8%A1%8C%28%E4%B8%9C%E4%BA%A4%E6%B0%91%E5%B7%B7%E5%82%A8%E8%93%84%E6%89%80%29","location":{"lat":"39.908091","lng":"116.413558"}," 本帖最后由 xuzuning 于 2014-06-05 08:59:55 编辑 你说过的方式我试过的了!网上其他一些避免乱码的也试过的!还是乱码了!我也刚接触PHP,所以很不多不理解!做的不好的请多见谅! 你说过的方式我试过的了!网上其他一些避免乱码的也试过的!还是乱码了!我也刚接触PHP,所以很不多不理解!做的不好的请多见谅!这样就可以了,上面那个多了一次json_encode。<?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,所以很不多不理解!做的不好的请多见谅!这样就可以了,上面那个多了一次json_encode。<?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);?>谢谢了啊!代码应该没问题了,我觉得我的文件设置的编码有问题!不过还是非常感谢你! 用CURL无法获取网易首页,求高手解答。。。谢谢 新手请教下各位前辈,下面这段代码的详细意思,谢谢! 手机短信用户回复规则的验证问题 htaccess的问题 求一个正则表达式 php类和对象的问题 推荐一个最好的游览器,不好用你就骂我 不知道这个问题能不能问。请问哪里可以扒到php的网站? 请问如何在php中进行跳转页面 如何在网站中插入表格 并实现搜索 select 怎么取到多个字段值 登录页面无法运行
$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"。。
array_walk_recursive($res, 'foo');
echo urldecode(json_encode($res));
现在在网页的页面能正确显示了!但是在txt中还是乱码!
[{"name":"%E4%B8%AD%E5%9B%BD%E5%B7%A5%E5%95%86%E9%93%B6%E8%A1%8C%28%E5%92%8C%E5%B9%B3%E9%97%A8%E5%86%85%E6%94%AF%E8%A1%8C%29","location":{"lat":"39.90742","lng":"116.390732"},"address":"%E5%8C%97%E4%BA%AC%E5%B8%82%E8%A5%BF%E5%9F%8E%E5%8C%BA%E5%8C%97%E6%96%B0%E5%8D%8E%E8%A1%97%E4%B8%9C%E6%9D%BE%E6%A0%91%E8%83%A1%E5%90%8C%E7%94%B231%E5%8F%B7"},{"name":"%E4%B8%AD%E5%9B%BD%E5%B7%A5%E5%95%86%E9%93%B6%E8%A1%8C%28%E4%B8%9C%E4%BA%A4%E6%B0%91%E5%B7%B7%E5%82%A8%E8%93%84%E6%89%80%29","location":{"lat":"39.908091","lng":"116.413558"},"
<?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);
?>
谢谢了啊!代码应该没问题了,我觉得我的文件设置的编码有问题!不过还是非常感谢你!