WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Convert a month to various formats (eg January, Jan, Ja, J, 1).
Categories : PHP, Date Time, Arrays Click here to Update Your Picture
Aris Karidis
Date : Jan 19th 2006
Grade : 3 of 5 (graded 2 times)
Viewed : 2776
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Aris Karidis
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?php
/**
* This function will convert an input month to various formats (eg January, Jan, Ja, J, 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 $month --> The month to be converted; a string or and array.
* @param int $format --> An integer specifying the format of the result (0->12, 1->D, 2->De, 3->Dec, 4->December).
* @return mixed --> string or array
*/
function convertMonth($month, $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();
    }
       
   
$january = array(1, 'j', 'ja', 'jan', 'january');
   
$february = array(2, 'f', 'fe', 'feb', 'february');
   
$march = array(3, 'm', 'ma', 'mar', 'march');
   
$april = array(4, 'a', 'ap', 'apr', 'april');
   
$may = array(5, 'm', 'ma', 'may', 'may');
   
$june = array(6, 'j', 'ju', 'jun', 'june');
   
$july = array(7, 'j', 'ju', 'jul', 'july');
   
$august = array(8, 'a', 'ag', 'aug', 'august');
   
$september = array(9, 's', 'se', 'sep', 'september');
   
$october = array(10, 'o', 'oc', 'oct', 'october');
   
$november = array(11, 'n', 'no', 'nov', 'november');
   
$december = array(12, 'd', 'de', 'dec', 'december');
       
   
$monthsOfTheYear = array($january, $february, $march, $april, $may, $june, $july,
                             
$august, $september, $october, $november, $december);
       
    if (!
is_array($month))
    {
       
$month = array(strtolower($month));
    }
   
   
$inputSize = count($month);   
   
    for (
$i = 0; $i < 12; $i++)
    {
       
$match = array_intersect($month, $monthsOfTheYear[$i]);
           
        if (!empty(
$match))
        {
            if (
$inputSize > 1)
            {
               
$result[] = ucfirst($monthsOfTheYear[$i][$format]);
            }
            else
            {
               
$result = ucfirst($monthsOfTheYear[$i][$format]);
                return
$result;
            }
        }
        else
        {
            if (
$i === 11)
            {
               
printf('Wrong parameter for $month.');
                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