十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
找一段天气预报代码,将返回的json代码通过连接语句插入到数据库中。
十年建站经验, 成都网站建设、网站制作客户的见证与正确选择。创新互联提供完善的营销型网页建站明细报价表。后期开发更加便捷高效,我们致力于追求更美、更快、更规范。
然后每天24点定时访问这个php链接就可以了。
var_dump(json_decode($json, true));
变成数组了应该就知道怎么调用了吧
?php
$URLStyle = "";
$chinaURL = sprintf($URLStyle, "china");
$chinaStr = file_get_contents($chinaURL);
$chinaObj = simplexml_load_string($chinaStr);
$chinaObjLen = count($chinaObj-city);
echo "chinaObjLen = ".$chinaObjLen."\n";
for ($i=0;$i$chinaObjLen;$i++){
//遍历省一级节点,共37个
$level1 = $chinaObj-city[$i]["pyName"];
$shengjiURL = sprintf($URLStyle, $level1);
$shengjiStr = file_get_contents($shengjiURL);
//echo $shengjiStr;
$shengjiObj = simplexml_load_string($shengjiStr);
$shengjiObjLen = count($shengjiObj-city);
// echo $chinaObj-city[$i]["quName"];
// echo " ".$shengjiObjLen."\n";
for ($j=0;$j$shengjiObjLen;$j++){
//遍历市一级节点
$level2 = $shengjiObj-city[$j]["pyName"];
$shijiURL = sprintf($URLStyle, $level2);
$shijiStr = file_get_contents($shijiURL);
//echo $shijiStr;
$shijiObj = simplexml_load_string($shijiStr);
//直辖市和海南、台湾、钓鱼岛等没有县级节点
if(!$shijiObj){
echo "WARNNING: not exsit next level node. - ".$level1."-".$shijiURL."\n";
echo ' "'.$shengjiObj-city[$j]["cityname"].'" = ';
echo $shengjiObj-city[$j]["url"].",\n";
continue;
}
$shijiObjLen = count($shijiObj-city);
//echo $shengjiObj-city[$j]["cityname"]." ";
//echo $shijiObjLen."\n";
for ($k=0;$k$shijiObjLen;$k++){
//遍历县一级节点
$xianji_code = $shijiObj-city[$k]["url"];
echo ' "'.$shijiObj-city[$k]["cityname"].'" = ';
echo $shijiObj-city[$k]["url"].",\n";
//echo $xianji_code."\n";
}
}
}
//print_r($chinaObj);
?
通过XML接口根节点递归获得全国几千个县以上城市cide code的代码