edo1z blog

プログラミングなどに関するブログです

googleで祝日取得(php)

参考:Google Calendar API で日本の祝日データを取得

private function get_syukujitsu($first_date, $end_date){
    $holidays_url = sprintf(
        'http://74.125.235.142/calendar/feeds/%s/public/full-noattendees?start-min=%s&start-max=%s&max-results=%d&alt=json' ,
        'outid3el0qkcrsuf89fltf7a4qbacgt9@import.calendar.google.com' ,
        $first_date,    // 取得開始日
        $end_date,    // 取得終了日
        7                // 最大取得数
    );
    if($results=file_get_contents($holidays_url)) {
        $results = json_decode($results, true);
        $holidays = array();
        if(isset($results['feed']['entry'])){
            foreach($results['feed']['entry'] as $val) {
                $date = $val['gd$when'][0]['startTime']; // 日付を取得
                $title = $val['title']['$t']; // 何の日かを取得
                $holidays[$date] = $title; // 日付をキーに、祝日名を値に格納
            }
        }
        ksort($holidays); // 日付順にソート
    }
    return $holidays;
}

$holidaysの中身

スクリーンショット 2014-03-26 8.44.41

要修正ですが、これで取得できた。googleありがとう。