[PHP] 공휴일 API
2020. 3. 20. 11:48ㆍPHP
<?
function getHoliday($year,$month) {
$ch = curl_init();
$url = 'http://apis.data.go.kr/B090041/openapi/service/SpcdeInfoService/getRestDeInfo'; // URL
$queryParams = '?' . urlencode('ServiceKey') . '=9GDyDS6rWCwiM0Os9v8qnajxhexefTgy4LWfXYSp%2FtHi5mM~~~~~~~~~~~~~~~~~~~~~~~'; // Service Key
$queryParams .= '&' . urlencode('solYear') . '=' . urlencode($year); // 연도
$queryParams .= '&' . urlencode('solMonth') . '=' . urlencode($month); // 월
curl_setopt($ch, CURLOPT_URL, $url . $queryParams);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$response = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($response);
$json = json_encode($xml);
$data = json_decode($json,true);
return $data;
}
for($i=1;$i<=12;$i++) {
$currentYear = date('Y');
$currentMonth = sprintf('%02d',$i);
$data = getHoliday($currentYear,$currentMonth);
foreach($data[body][items] as $val) {
// 데이터 가공 후 사용하면 된다.
}
}
?>
'PHP' 카테고리의 다른 글
[PHP] 캔버스 이미지 업로드 (0) | 2020.06.23 |
---|---|
[PHP] flush를 이용한 디버그 메세지 출력 (0) | 2020.04.03 |
[PHP] 메모리 무제한 설정 (0) | 2020.04.03 |
[PHP] base64 데이터를 이미지로 저장하기 (0) | 2020.03.20 |
[PHP] 유튜브 API (0) | 2020.03.20 |