Traditional Culture Encyclopedia - Weather inquiry - Php gets the code of weather forecast.

Php gets the code of weather forecast.

& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)

$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.