<?php
/**
* Find the day of the week for any given year/month/day.
* $calendarSystem specifies the calendar system
* 0 = Julian calendar
* 1 = Gregorian calendar
*
* @param int $day
* @param int $month
* @param int $year
* @param int $calendarSystem
* @return int
*/
function getDayOfWeek($day, $month, $year, $calendarSystem = 1)
{
# Check for valid parameters #
if (!is_int($day) || $day < 1 || $day > 31)
{
printf('Wrong parameter for $day. It must be an integer between 1 and 31.');
exit();
}
if (!is_int($month) || $month < 1 || $month > 12)
{
printf('Wrong parameter for $month. It must be an integer between 1 and 12.');
exit();
}
if (!is_int($year) || $year < 0)
{
printf('Wrong parameter for $year. It must be a positive integer.');
exit();
}
if (!checkdate($month, $day, $year))
{
printf('Invalid date.');
exit();
}