$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);
?>
I can only export all the information to the local TXT now! Just do not understand how to judge the output of the 3 messages into the local TXT! Ask for guidance
Reply to discussion (solution)
$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));
+1
Great God, thank you very much! But why am I outputting a bunch of garbled, hungry? [{"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));
Great God, thank you very much! But why am I outputting a bunch of garbled, hungry? [{"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 ".....
Deal with it.
function foo (& $v) {$v = UrlEncode ($v);} Array_walk_recursive ($res, ' foo '); Echo UrlDecode (Json_encode ($res));
Deal with it.
function foo (& $v) {$v = UrlEncode ($v);} Array_walk_recursive ($res, ' foo '); Echo UrlDecode (Json_encode ($res));
Now the page in the page can be displayed correctly! But in TXT or garbled!
[{"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 "},"
Didn't you save the results of Echo?
function foo (& $v) {$v = UrlEncode ($v);} Array_walk_recursive ($res, ' foo '); $t = UrlDecode (Json_encode ($res)); File_put_contents (' A1.txt ', $t);
To be honest, people who are not flexible, are not suitable for programmers.
Didn't you save the results of 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));
To be honest, people who are not flexible, are not suitable for programmers.
I tried the way you said it! Some of the other online to avoid garbled also tried! It's still garbled! I also just touch php, so very little do not understand! Please forgive me for not doing well.
Didn't you save the results of 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));
To be honest, people who are not flexible, are not suitable for programmers.
I tried the way you said it! Some of the other online to avoid garbled also tried! It's still garbled! I also just touch php, so very little do not understand! Please forgive me for not doing well.
This will do, the above one more json_encode.
', ' 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);? >
Didn't you save the results of 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));
To be honest, people who are not flexible, are not suitable for programmers.
I tried the way you said it! Some of the other online to avoid garbled also tried! It's still garbled! I also just touch php, so very little do not understand! Please forgive me for not doing well.
This will do, the above one more json_encode.
', ' 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);? >
Thank you, Ah! The code should be no problem, I think my file settings have a problem with the encoding! But thank you very much!