calendar
Example to demonstrate how to create an API on your PHP program
home
API that return a calendar.
Here is the PHP code corresponding implementation. (/api/calendar/index.php)
<?php // index.html
include 'lib.php';
$year_month_regex="#^/api\/calendar/([12]\d{3}/(0[1-9]|1[0-2]))$#";
if (preg_match($year_month_regex,$_SERVER['REQUEST_URI'],$match))
{
header_no_cache();
header('Content-type: application/json; charset=utf-8');
$cal = explode("/", substr($match[0],-8));
$annee=$cal[0];
$mois =$cal[1];
$infos=new stdClass();
$infos->month = $mois;
$infos->year = $annee;
$infos->days_in_month = date('j', mktime(0,0,0,$mois+1,0,$annee));
$infos->first_day_of_the_month = date('D', mktime(0,0,0,$mois,1,$annee));
$infos->events=my_calendar($mois,$annee);
echo json_encode($infos);
}
?>
Here is the .htaccess file ton configure you apache HTTP Server:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /api/calendar/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /api/calendar/index.php
</IfModule>