기상청 날씨정보 XML

http://www.kma.go.kr/XML/weather/sfc_web_map.xml

기상청 날씨정보에 관한 질답 http://kldp.org/node/76834
[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]
|

댓글 7개

해당지역 날씨를 인쿨루드해서 쓸려면 어캐 해요???? XML은 잘 몰라서요 ;;;
fsockopen이나 파일오픈해서 판단해주는수밖에 없죠;;
근데 저거 금방없어질 예감인데 ㅋㅋ;;
흠..날씨배너 복잡한 방식보다는 쉬운 방법도 있어요

날씨배너 색상별 지역별 75종 kweather 걸루 만들어 봤는데 구경오세요

kweather 은 회원가입도 해야하고 절차가 복잡하니 제 것 가져다 쓰세요

제것은 누르면 음악플레이어도 나옵니다.. 쩝..

http://blog.paran.com/necast/24428191
//저 링크로 날씨 정보 끌어 오는 소스입니다.

function make_weather(){

srand((double)microtime()*1000000);
$boundary = "---------------------".substr(md5(rand(0,32000)),0,10);
$header = "POST /XML/weather/sfc_web_map.xml HTTP/1.0\r\n";
$header .= "Host: kma.go.kr\r\n";
$header .= "Content-type: multipart/form-data, boundary=".$boundary."\r\n";

/*
// 본문 생성
foreach($sms AS $index => $value){
$data .="--$boundary\r\n";
$data .= "Content-Disposition: form-data; name=\"".$index."\"\r\n";
$data .= "\r\n".$value."\r\n";
$data .="--$boundary\r\n";
}
*/
$header .= "Content-length: " . strlen($data) . "\r\n\r\n";

$fp = fsockopen('kma.go.kr', 80);

if ($fp) {
fputs($fp, $header.$data);
$rsp = '';
while(!feof($fp)) {
$rsp .= fgets($fp,8192);
}
fclose($fp);
$msg = explode("\r\n\r\n",trim($rsp));
$rMsg = explode(",", $msg[1]);
}

$xmldoc = new DOMDocument();
$xmldoc->loadXML($msg[1]);

$local_dom_result = $xmldoc->getElementsByTagName('local');

$result = array();
foreach($local_dom_result as $subkey){
$ta = $subkey->getAttribute('ta');
$icon = $subkey->getAttribute('icon');
$name = iconv("UTF-8", "euckr",$subkey->nodeValue);
$result[$name]=array('icon'=>$icon, 'ta'=>$ta);
}

return $result;
}

// 결과 값은.
array(
array('속초'=>array('icon'=>'01', 'ta'=>'20.93'),
array('서울'=>array('icon'=>'02', 'ta'=>'24.93'),
);

형태 입니다.

디자이너가 어디서 날씨 스크롤 플래쉬소스를 떡하니 붙여 놔서 할수 없이 작업해야 했습니다.

icon을 넣는 이유는 아이콘도 기상청에서 제공하는 날씨 아이콘 숫자처럼 01.gif, 02.gif 로 있더군

요. 정확하게 매치되네요.

euc-kr 용이며, utf-8에서는 그냥 iconv 만 빼면 됩니다.

php.5.1 이상에서 작동하며, 이유는 simplexml 보다는 domdocument 가 나름 다루기 편해서입니다.
헉 제가 찾고있던 부분이에요
//저 링크로 날씨 정보 끌어 오는 소스입니다.

function make_weather(){

srand((double)microtime()*1000000);
$boundary = "---------------------".substr(md5(rand(0,32000)),0,10);
$header = "POST /XML/weather/sfc_web_map.xml HTTP/1.0\r\n";
$header .= "Host: kma.go.kr\r\n";
$header .= "Content-type: multipart/form-data, boundary=".$boundary."\r\n";

/*
// 본문 생성
foreach($sms AS $index => $value){
$data .="--$boundary\r\n";
$data .= "Content-Disposition: form-data; name=\"".$index."\"\r\n";
$data .= "\r\n".$value."\r\n";
$data .="--$boundary\r\n";
}
*/
$header .= "Content-length: " . strlen($data) . "\r\n\r\n";

$fp = fsockopen('kma.go.kr', 80);

if ($fp) {
fputs($fp, $header.$data);
$rsp = '';
while(!feof($fp)) {
$rsp .= fgets($fp,8192);
}
fclose($fp);
$msg = explode("\r\n\r\n",trim($rsp));
$rMsg = explode(",", $msg[1]);
}

$xmldoc = new DOMDocument();
$xmldoc->loadXML($msg[1]);

$local_dom_result = $xmldoc->getElementsByTagName('local');

$result = array();
foreach($local_dom_result as $subkey){
$ta = $subkey->getAttribute('ta');
$icon = $subkey->getAttribute('icon');
$name = iconv("UTF-8", "euckr",$subkey->nodeValue);
$result[$name]=array('icon'=>$icon, 'ta'=>$ta);
}

return $result;
}

// 결과 값은.
array(
array('속초'=>array('icon'=>'01', 'ta'=>'20.93'),
array('서울'=>array('icon'=>'02', 'ta'=>'24.93'),
);

형태 입니다.

디자이너가 어디서 날씨 스크롤 플래쉬소스를 떡하니 붙여 놔서 할수 없이 작업해야 했습니다.

icon을 넣는 이유는 아이콘도 기상청에서 제공하는 날씨 아이콘 숫자처럼 01.gif, 02.gif 로 있더군

요. 정확하게 매치되네요.

euc-kr 용이며, utf-8에서는 그냥 iconv 만 빼면 됩니다.

php.5.1 이상에서 작동하며, 이유는 simplexml 보다는 domdocument 가 나름 다루기 편해서입니다.


네발가락님 짱^^
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
17년 전 조회 1,765
17년 전 조회 1,902
17년 전 조회 3,032
17년 전 조회 2,174
17년 전 조회 1,843
17년 전 조회 2,190
17년 전 조회 1,910
17년 전 조회 3,441
17년 전 조회 1,618
17년 전 조회 1,723
17년 전 조회 1,437
17년 전 조회 2,272
17년 전 조회 3,211
17년 전 조회 2,357
17년 전 조회 1,811
17년 전 조회 3,062
17년 전 조회 4,536
17년 전 조회 1,827
17년 전 조회 3,339
17년 전 조회 1,647
17년 전 조회 3,574
17년 전 조회 5,933
17년 전 조회 1,490
17년 전 조회 2,238
17년 전 조회 1,859
17년 전 조회 1,606
17년 전 조회 2,508
17년 전 조회 2,695
18년 전 조회 1,663
18년 전 조회 2,769
18년 전 조회 3,262
18년 전 조회 1,588
18년 전 조회 2,015
18년 전 조회 3,933
18년 전 조회 4,564
18년 전 조회 1,946
18년 전 조회 1,802
18년 전 조회 2,753
18년 전 조회 1,940
18년 전 조회 4,014
18년 전 조회 1,709
16년 전 조회 2,004
18년 전 조회 2,325
18년 전 조회 2,203
18년 전 조회 3,665
18년 전 조회 1,657
18년 전 조회 2,743
18년 전 조회 1,726
18년 전 조회 1,984
18년 전 조회 7,519
18년 전 조회 2,089
18년 전 조회 4,180
18년 전 조회 2,514
18년 전 조회 2,513
18년 전 조회 2,231
18년 전 조회 2,293
18년 전 조회 2,714
18년 전 조회 3,306
18년 전 조회 5,402
18년 전 조회 2,855
18년 전 조회 2,778
18년 전 조회 2,631
18년 전 조회 1,882
18년 전 조회 2,287
18년 전 조회 5,398
18년 전 조회 3,104
18년 전 조회 2,670
18년 전 조회 3,355
18년 전 조회 2,551
18년 전 조회 2,910
18년 전 조회 5,938
18년 전 조회 2,695
18년 전 조회 2,087
18년 전 조회 2,734
18년 전 조회 1,556
18년 전 조회 9,883
18년 전 조회 4,551
18년 전 조회 3,364
18년 전 조회 1,900
18년 전 조회 3,681
18년 전 조회 2,369
18년 전 조회 3,816
18년 전 조회 5,255
18년 전 조회 3,908
18년 전 조회 2,747
18년 전 조회 3,026
18년 전 조회 2,529
18년 전 조회 2,872
18년 전 조회 1,979
18년 전 조회 3,516
18년 전 조회 2,209
18년 전 조회 2,343
18년 전 조회 2,172
18년 전 조회 3,132
18년 전 조회 2,071
18년 전 조회 2,743
18년 전 조회 3,932
18년 전 조회 4,645
18년 전 조회 2,452
18년 전 조회 2,933