phpでgoogleAPIから日本の休日を取得する


<?php

//今年
$toyear = date(“Y”);
$toyear1=”$toyear”.”-01-01″;
$toyear2=”$toyear”.”-12-31″;

$holidays_url = sprintf(
‘http://www.google.com/calendar/feeds/%s/public/full-noattendees?start-min=%s&start-max=%s&max-results=%d&alt=json’ ,
‘outid3el0qkcrsuf89fltf7a4qbacgt9@import.calendar.google.com’ , ,
“$toyear1” , // 取得開始日
“$toyear2″ , // 取得終了日
50 // 最大取得数
);
if ( $results = file_get_contents($holidays_url) ) {
$results = json_decode($results, true);
$holidays = array();
foreach ($results[‘feed’][‘entry’] as $val ) {
$date = $val[‘gd$when’][0][‘startTime’];
$title = $val[‘title’][‘$t’];
$title = preg_replace(‘!/[^/]*!’, ‘/’, $title);
$title = str_replace(‘/’, ”, $title);
$holidays[$date] = $title;

 

}
ksort($holidays);
foreach($holidays as $key => $value){

echo $key.” “.$value.”<br />”;
}

}
phpで日本の祝日や振替休日を出力する。

コメントを残す

メールアドレスが公開されることはありません。