|
|
|
|
|
|
| |
| <?php
/**
* This function will convert an input day to various formats (eg Monday, Mon, Mo, M, 1).
* It accepts a string or an array as input and returns a string or an array. Be careful
* when using an array with non-unique elements.
*
* @param mixed $day --> The day to be converted; a string or and array.
* @param int $format --> An integer specifying the format of the result (0->7, 1->S, 2->Su, 3->Sun, 4->Sunday).
* @return mixed --> string or array
*/
function convertDay($day, $format)
{
# Check for valid parameters #
if ($format !== 0 && $format !== 1 && $format !== 2 && $format !== 3 && $format !== 4)
{
printf('Wrong parameter for $format. This must be 0, 1, 2, 3 or 4.');
exit();
}
$monday = array(1, 'm', 'mo', 'mon', 'monday');
$tuesday = array(2, 't', 'tu', 'tue', 'tuesday');
$wednesday = array(3, 'w', 'we', 'wed', 'wednesday');
$thursday = array(4, 't', 'th', 'thu', 'thursday');
$friday = array(5, 'f', 'fr', 'fri', 'friday');
$saturday = array(6, 's', 'sa', 'sat', 'saturday');
$sunday = array(7, 's', 'su', 'sun', 'sunday');
$daysOfTheWeek = array($monday, $tuesday, $wednesday, $thursday, $friday, $saturday, $sunday);
if (!is_array($day))
{
$day = array(strtolower($day));
}
$inputSize = count($day);
for ($i = 0; $i < 7; $i++)
{
$match = array_intersect($day, $daysOfTheWeek[$i]);
if (!empty($match))
{
if ($inputSize > 1)
{
$result[] = ucfirst($daysOfTheWeek[$i][$format]);
}
else
{
$result = ucfirst($daysOfTheWeek[$i][$format]);
return $result;
}
}
else
{
if ($i === 6)
{
printf('Wrong parameter for $day.');
exit();
}
}
}
return $result;
}
?> | | |
|
| enhanced date picker with jcript checking for a dynamic date input Categories : PHP, Java Script, Date Time, Calendar, Arrays | | | Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP, Arrays, Date Time, Databases, MySQL | | | Function that returns an array with the 7 dates of the week that belong to the supplied date. Categories : PHP, Date Time, Arrays | | | Select with current month Categories : PHP, HTML and PHP, Date Time, Arrays | | | PHP Script to find url links in a page Categories : PHP, URLs, Regexps, Arrays | | | Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | | | Array values from javascript to php Categories : PHP, Java Script, Arrays | | | A Timing Class Categories : PHP, PHP Classes, Date Time | | | clearing variables in php3 Categories : Variables, Arrays, PHP | | | Weighted Random - Random Scripts usually chose one out of each item, and each item have an equal chance to be chosen. But what if you want an item to be chosed more frequently than other? Categories : PHP, Math., Arrays | | | Finding the day of the week for a specific date.
Categories : PHP, Databases, MySQL, Date Time | | | Display list of files within current and subdirectories (recursively) showing
each file as an anchored link and each directory as a category header. Categories : Filesystem, Directories, Arrays, PHP | | | A wrapper function to format dates coming from a databases with the
same syntax as PHP's date() function. Categories : Date Time, Databases, PHP | | | pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes | | | A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function. Categories : PHP, PHP Classes, Calendar, Date Time | |
|
|
|