XML 지역 별 날씨 상황 에 대한 자세 한 정보 및 분석 데 이 터 를 입고 합 니 다.
파일 이름: city. php
/ / 지역 별 날씨 상황 입고 실현
<?php
header("content-type:text/html;charset=utf-8");
$dsn="mysql:dbname=news;host=127.0.0.1;charset=utf8";
$user="root";
$psw="";
$pdo=new PDO($dsn,$user,$psw);
$url = "http://flash.weather.com.cn/wmaps/xml/china.xml";
//
$dom=new DOMDocument();
//print_r($dom);die;
$dom->load($url);
//
$city=$dom->getElementsByTagName("city");
//print_r($city);die;
$len = $city->length;
for($i=0;$i<$len;$i++){
$item = $city->item($i);
$quName = $item->getAttribute("quName");
//print_r($quName);die;
$pyName = $item->getAttribute("pyName");
$cityname = $item->getAttribute("cityname");
$state1 = $item->getAttribute("state1");
$state2 = $item->getAttribute("state2");
$stateDetailed = $item->getAttribute("stateDetailed");
$tem1 = $item->getAttribute("tem1");
$tem2 = $item->getAttribute("tem2");
$windState = $item->getAttribute("windState");
// sql
$sql = "insert into weather(quName,pyName,cityname,state1,state2,stateDetailed,tem1,tem2,windState)values('".$quName."','".$pyName."','".$cityname."','".$state1."','".$state2."','".$stateDetailed."','".$tem1."','".$tem2."','".$windState."')";
// sql
set_time_limit(0);//
$res = $pdo->exec($sql);
//
$dom1=new DOMDocument();
@$dom1->load("http://flash.weather.com.cn/wmaps/xml/".$pyName.".xml");
$citys=$dom1->getElementsByTagName("city");
$leng = $citys->length;
for($j=0;$j<$leng;$j++){
$item1 = $citys->item($j);
$cityX = $item1->getAttribute("cityX");
$cityY = $item1->getAttribute("cityY");
$cityname = $item1->getAttribute("cityname");
$centername = $item1->getAttribute("centername");
$fontColor = $item1->getAttribute("fontColor");
$pyName = $item1->getAttribute("pyName");
$state1 = $item1->getAttribute("state1");
$state2 = $item1->getAttribute("state2");
$stateDetailed = $item1->getAttribute("stateDetailed");
$tem1 = $item1->getAttribute("tem1");
$tem2 = $item1->getAttribute("tem2");
$temNow = $item1->getAttribute("temNow");
$windState = $item1->getAttribute("windState");
$windDir = $item1->getAttribute("windDir");
$windPower = $item1->getAttribute("windPower");
$humidity = $item1->getAttribute("humidity");
$time = $item1->getAttribute("time");
$url = $item1->getAttribute("url");
//var_dump($humidity);die;
$sql1 = "insert into sheng(cityX,cityY,cityname,centername,fontColor,pyName,state1,state2,stateDetailed,tem1,tem2,temNow,windState,windDir,windPower,humidity,time,url)values('".$cityX."','".$cityY."','".$cityname."','".$centername."','".$fontColor."','".$pyName."','".$state1."','".$state2."','".$stateDetailed."','".$tem1."','".$tem2."','".$temNow."','".$windState."','".$windDir."','".$windPower."','".$humidity."','".$time."','".$url."')";
set_time_limit(0);//
//$data = $pdo->exec($sql1);
//
$dom2=new DOMDocument();
@$dom2->load("http://flash.weather.com.cn/wmaps/xml/".$pyName.".xml");
$city1=$dom2->getElementsByTagName("city");
$length = $city1->length;
//print_r($length);
for($s=0;$s<$length;$s++){
$item2 = $city1->item($s);
$cityX = $item2->getAttribute("cityX");
$cityY = $item2->getAttribute("cityY");
$cityname = $item2->getAttribute("cityname");
$centername = $item2->getAttribute("centername");
$fontColor = $item2->getAttribute("fontColor");
$pyName = $item2->getAttribute("pyName");
$state1 = $item2->getAttribute("state1");
$state2 = $item2->getAttribute("state2");
$stateDetailed = $item2->getAttribute("stateDetailed");
$tem1 = $item2->getAttribute("tem1");
$tem2 = $item2->getAttribute("tem2");
$temNow = $item2->getAttribute("temNow");
$windState = $item2->getAttribute("windState");
$windDir = $item2->getAttribute("windDir");
$windPower = $item2->getAttribute("windPower");
$humidity = $item2->getAttribute("humidity");
$time = $item2->getAttribute("time");
$url = $item2->getAttribute("url");
$sql2 = "insert into sheng(cityX,cityY,cityname,centername,fontColor,pyName,state1,state2,stateDetailed,tem1,tem2,temNow,windState,windDir,windPower,humidity,time,url)values('".$cityX."','".$cityY."','".$cityname."','".$centername."','".$fontColor."','".$pyName."','".$state1."','".$state2."','".$stateDetailed."','".$tem1."','".$tem2."','".$temNow."','".$windState."','".$windDir."','".$windPower."','".$humidity."','".$time."','".$url."')";
set_time_limit(0);//
$data1 = $pdo->exec($sql2);
}
}
}
?>
2. XML 이벤트 기반 지역 별 날씨 정보 순환: jiexi. php
<?php
header("content-type:text/html;charset=utf-8");
$file = 'http://flash.weather.com.cn/wmaps/xml/china.xml';
$stack = array();
function startTag($parser, $name, $attrs)
{
global $stack;
$tag=array("name"=>$name,"attrs"=>$attrs);
array_push($stack,$tag);
}
function cdata($parser, $cdata)
{
global $stack,$i;
if(trim($cdata))
{
$stack[count($stack)-1]['cdata']=$cdata;
}
}
function endTag($parser, $name)
{
global $stack;
$stack[count($stack)-2]['children'][] = $stack[count($stack)-1];
array_pop($stack);
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "cdata");
$data = xml_parse($xml_parser,file_get_contents($file));
if(!$data) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
xml_parser_free($xml_parser);
print("<pre>
");
print_r($stack);
print("</pre>
");
?>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
json 날씨 정보 분석(중앙 기상대)텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.