Traditional Culture Encyclopedia - Weather inquiry - Php gets the code of weather forecast.
Php gets the code of weather forecast.
$URLStyle? =? "/wmaps/XML/% s . XML ";
$chinaURL? =? sprintf($URLStyle,? "China");
$chinaStr? =? file _ get _ contents($ China URL);
$chinaObj? =? SimpleXML _ load _ string($ chinaStr);
$chinaObjLen? =? count($ China obj-& gt; City);
Echo? “chinaObjLen? =? "。 $chinaObjLen。 ”\ n”;
For what? ($ I = 0; $ i & lt$ chinaObjLen$i++){
//Traverse provincial nodes, ***37.
$level 1? =? $ China obj-& gt; city[$ I][" pyName "];
$ shengjiURL? =? sprintf($URLStyle,? $ level 1);
$ St. Gierster? =? file _ get _ contents($ shejiurl);
//echo? $ jigstr;
$ shengjiObj? =? SimpleXML _ load _ string($ shengistr); ?
$ shengjiObjLen? =? count($sanjiobj-& gt; City);
//echo? $ China obj-& gt; City [$ i] ["quname"];
//echo? "?" . $ shengjiObjLen。 ”\ n”;
For what? ($ j = 0; $ j & lt$ shengjiObjLen$j++){
//Traverse the municipal nodes
$level2? =? $ sanjiobj-& gt; city[$ j][" pyName "];
$shijiURL? =? sprintf($URLStyle,? $ level 2);
$shijiStr? =? file _ get _ contents($ shijiURL);
//echo? $ shijiStr
$shijiObj? =? SimpleXML _ load _ string($ shiji str); ?
//There are no county-level nodes in municipalities directly under the Central Government, Hainan, Taiwan Province Province and Diaoyu Island.
If (! $shijiObj){
Echo? "Warning:? Isn't it? exsit? Next? Level? Nodes. ? -? "。 $level 1。" -".$shijiURL。 ”\ n”;
Echo? '"'.$ sanjiobj-& gt; City [$j]["cityname"]. "? = & gt? ;
Echo? $ sanjiobj-& gt; City [$j]["url"]. ",\ n ";
Continue;
}
$shijiObjLen? =? count($shijiObj-& gt; City);
//echo? $ sanjiobj-& gt; City [$j]["cityname"]. "";
//echo? $shijiObjLen。 ”\ n”;
For what? ($ k = 0; $ k & lt$ shijiObjLen$k++){
//Traverse the county-level nodes
$ Ji Xian _ code? =? $ shijiObj-& gt; City [$ k] ["URL"];
Echo? '"'.$ shijiObj-& gt; City [$k]["cityname"]. "? = & gt? ;
Echo? $ shijiObj-& gt; City [$k]["url"]. ",\ n ";
//echo? $ Ji Xian _ code. ”\ n”; ?
}
}
}?
//print _ r($ China obj);
> The cide codes of thousands of cities above county level in China are obtained recursively through the root node of XML interface.
- Previous article:Where is Leshan cherry picking garden?
- Next article:China go on road trip Classic Roadmap recommends 27 popular opportunities to try.
- Related articles
- What does Yuanbao mean?
- It's hot, why do you always feel irritable?
- How to get rid of acne and acne marks
- If the weather cannot find a location, please ask siri.
- What famous scientific and technological stars were there in ancient China?
- Harmony accident
- Write a composition about eating people in the zoo.
- How to display the time and weather on the desktop of vivo mobile phone?
- Where is the most spectacular maple forest in China?
- The weather forecast for Chongming is 15 days.