PHP & Others

XML을 이용한 날씨 출력

컨텐츠 정보

본문

미리보기 :  http://cien.dnip.net/weather.php



<?php

header("Content-Type: text/html; charset=UTF-8");

$weather_xml = "http://www.kma.go.kr/weather/xml/current.xml";

$lines = array_slice(file($weather_xml), 5);
$pattern = '/<local desc="([^"]*)" icon="[^"]*" stn_id="[^"]*" ta="([^"]*)">(.+)<\\/local>/';
foreach ($lines as $line) {
    preg_match($pattern, $line, $weather);
    if (count($weather) < 3) break;
    list($area, $status, $temp) = $weather;
    echo "$area : $temp, $status<br />";
}

?>

치즈버거님께서 알려주신 주소(http://www.kma.go.kr/weather/xml/current.xml)를 사용했습니다. (기상청 제공)
주의하실 점은, 출력할때는 반드시 UTF-8 인코딩으로 출력하시거나 iconv로 EUC-KR로 변환시키세요. (EUC-KR 인코딩으로 바꾸셨을 때는 헤더 출력 부분을 빼주세요.

 
기상청에 문의해 보시면 압니다.
상용 사이트에는 일체 자료 제공을 하지 않겠다고했습니다..
고발당해서 크게 당합니다..
필요하시면 기상정보를 제공해주는 업체가 있으니 거기랑 계약해야합니다..

관련자료

댓글 0
등록된 댓글이 없습니다.
Today's proverb
학문의 최대의 적은 자기 마음속에 있는 유혹이다. (처칠)