기상청 날씨정보 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,721
17년 전 조회 1,862
17년 전 조회 2,990
17년 전 조회 2,136
17년 전 조회 1,809
17년 전 조회 2,149
17년 전 조회 1,866
17년 전 조회 3,405
17년 전 조회 1,571
17년 전 조회 1,696
17년 전 조회 1,413
17년 전 조회 2,232
17년 전 조회 3,169
17년 전 조회 2,319
17년 전 조회 1,773
17년 전 조회 3,032
17년 전 조회 4,483
17년 전 조회 1,789
17년 전 조회 3,285
17년 전 조회 1,613
17년 전 조회 3,530
17년 전 조회 5,881
17년 전 조회 1,455
17년 전 조회 2,200
17년 전 조회 1,823
17년 전 조회 1,575
17년 전 조회 2,461
17년 전 조회 2,670
18년 전 조회 1,632
18년 전 조회 2,725
18년 전 조회 3,205
18년 전 조회 1,561
18년 전 조회 1,982
18년 전 조회 3,888
18년 전 조회 4,518
18년 전 조회 1,914
18년 전 조회 1,769
18년 전 조회 2,717
18년 전 조회 1,889
18년 전 조회 3,969
18년 전 조회 1,677
16년 전 조회 1,972
18년 전 조회 2,297
18년 전 조회 2,150
18년 전 조회 3,605
18년 전 조회 1,622
18년 전 조회 2,692
18년 전 조회 1,679
18년 전 조회 1,948
18년 전 조회 7,465
18년 전 조회 2,032
18년 전 조회 4,129
18년 전 조회 2,455
18년 전 조회 2,471
18년 전 조회 2,192
18년 전 조회 2,233
18년 전 조회 2,655
18년 전 조회 3,247
18년 전 조회 5,362
18년 전 조회 2,817
18년 전 조회 2,737
18년 전 조회 2,584
18년 전 조회 1,832
18년 전 조회 2,238
18년 전 조회 5,348
18년 전 조회 3,060
18년 전 조회 2,622
18년 전 조회 3,300
18년 전 조회 2,518
18년 전 조회 2,873
18년 전 조회 5,903
18년 전 조회 2,652
18년 전 조회 2,048
18년 전 조회 2,687
18년 전 조회 1,510
18년 전 조회 9,846
18년 전 조회 4,491
18년 전 조회 3,328
18년 전 조회 1,848
18년 전 조회 3,644
18년 전 조회 2,315
18년 전 조회 3,768
18년 전 조회 5,207
18년 전 조회 3,871
18년 전 조회 2,702
18년 전 조회 2,976
18년 전 조회 2,487
18년 전 조회 2,822
18년 전 조회 1,931
18년 전 조회 3,476
18년 전 조회 2,166
18년 전 조회 2,298
18년 전 조회 2,119
18년 전 조회 3,090
18년 전 조회 2,033
18년 전 조회 2,696
18년 전 조회 3,900
18년 전 조회 4,603
18년 전 조회 2,411
18년 전 조회 2,886