구글날씨 정보XML 받아서 홈페이지에 출력하는 방법
– 한 5년전 자료이다. 그래도 백업해본다~
<?php echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">'; ## 한글utf-8함수 ############################# function koutf($kor){ $return = iconv("EUC-KR","UTF-8", $kor); return $return; } ############################################ $xml_data= @file_get_contents('http://www.google.co.kr/ig/api?weather=seoul'); $xml_data = iconv("EUC-KR","UTF-8", $xml_data); $tst = new SimpleXMLElement ($xml_data); // children 값 구할때 ## SimpleXMLElement::children /* foreach ($tst->children() as $child) { echo $child->getName() . " "; //echo "no of array:"; //echo count($tst)." "; foreach ($child->children() as $childz) { //echo "no of array:"; //echo count($child)." "; echo $childz->getName() . " "; } } */ //지역 $area = $tst->weather[0]->forecast_information[0]->city->attributes()->data; // 지역 echo strtoupper($area) ; echo ""; echo koutf("현재날씨"); //echo $tst->weather[0]->forecast_information[0]->city->attributes()->data; //도시. 서울의셩우 필요없어서 주석처리 echo ""; echo $tst->weather[0]->forecast_information[0]->current_date_time->attributes()->data; //날짜 echo ""; echo $tst->weather[0]->current_conditions[0]->temp_c->attributes()->data; //금일온도 echo ""; echo $tst->weather[0]->current_conditions[0]->humidity->attributes()->data; //습도 echo ""; echo $tst->weather[0]->current_conditions[0]->wind_condition->attributes()->data; //바람 echo ""; echo ""; //4일예보 echo koutf("날씨예보"); for ($i=0;$i<=3;$i++){ echo $tst->weather[0]->forecast_conditions[$i]->day_of_week->attributes()->data; //날짜 echo ""; echo koutf("최저: ").$tst->weather[0]->forecast_conditions[$i]->low->attributes()->data; //최저 echo ""; echo koutf("최고: ").$tst->weather[0]->forecast_conditions[$i]->high->attributes()->data; //최고 echo ""; echo ""; //이미지 echo ""; echo $tst->weather[0]->forecast_conditions[$i]->condition->attributes()->data; //상태 echo ""; } ?>
구글날씨 정보XML 받아서 홈페이지에 출력하는 방법 ( weather.com을 추천한다.)