PHP online calendar, PHP calendar, flexible use of PHPstrtotime to generate a simple calendar
PHP online calendar implementation
The following is the code. please forgive me because I have a limited level and the code is not perfect!
* @ Version $ Id: calendar. php, v 1.0 15:12:00 uw Exp * @ copyright©2011, xudianyang * // *** PHP generates a simple online calendar ** @ param string $ language calendar language. The value is EN, which indicates English and the value is CN, HTML code */define ("EMPTY_COLUMN", ""); header ("content-type: text/html; charset = gb2312 "); function php_calendar ($ language = 'en') {$ lang = array ('en', 'cn'); if (! In_array ($ language, $ lang) {$ language = "EN" ;}$ months = array ('January ', 'February', 'March', 'cmdl ', 'May', 'June', 'July', 'August ', 'September', 'October ', 'November', 'December '); $ EN = array ('month' => array ('January '=> 'January', 'February '=> 'February', 'march' => 'March ', 'cmdl' => 'cmdl', 'may' => 'May', 'June' => 'June', 'July' => 'July ', 'August '=> 'August', 'September '=> 'September', 'October '=> 'October', 'November '=> 'November', 'December' => 'December',), 'Week '=> array ('mon' => 'Mon', 'tue' => 'tue ', 'wed' => 'Wed', 'Thu' => 'Thu', 'Fri' => 'Fri', 'sat => 'sat ', 'sun' => 'Sun'), 'Today' => 'Today ',); $ CN = array ('month' => array ('January '=> 'octoken', 'February' => 'octoken', 'march' => 'octoken ', '0000l' => 'August 11', 'may' => 'August 11', 'June' => 'August 11', 'July' => 'August 11 ', 'August '=> 'August 11', 'September '=> 'August 11', 'October' => 'August 11', 'November 11' => 'August 11 ', 'December' => 'August 11',), 'week' => array ('mon' => 'Monday', 'Tuesday => ', 'Wed' => 'wedday', 'Thu' => 'thurs', 'Fri' => 'Friday', 'sat' => 'satur ', 'sunsun' => 'Sunday'), 'Today' => 'go to today',); if (isset ($ _ GET ['month']) & in_array ($ _ GET ['month'], $ months) {$ month = $ _ GET ['month'];} else {$ month = date ("F");} if (isset ($ _ GET ['Year']) & is_numeric ($ _ GET ['Year']) & $ _ GET ['Year'] <= 2038 & $ _ GET ['Year']> = 1970) {$ year = $ _ GET ['Year'];} else {$ year = date ("Y ");} $ start = strtotime ("$ month 1st $ year"); $ end = strtotime ("$ month ". d Ate ("t", $ start ). "$ year"); $ previus_year = strtotime ("-1 year", $ start); $ next_year = strtotime ("+ 1 year", $ start ); $ previus_month = strtotime ("-1 month", $ start); $ next_month = strtotime ("+ 1 month", $ start); $ link = "% s "; if (date ("Y", $ previus_year) >=1970) {$ calendar [] = sprintf ($ link, date ("F", $ start ), date ("Y", $ previus_year), date ("Y", $ previus_year);} else {$ calendar [] = EMPTY_COLUMN;} $ calendar [] = EMPTY_COLUMN; $ calenda R [] = EMPTY_COLUMN; $ calendar [] = date ("Y", $ start); $ calendar [] = EMPTY_COLUMN; $ calendar [] = EMPTY_COLUMN; if (date ("Y", $ next_year) <2038 & date ("Y", $ next_year )! = 1969) {$ calendar [] = sprintf ($ link, date ("F", $ start), date ("Y", $ next_year), date ("Y ", $ next_year);} else {$ calendar [] = EMPTY_COLUMN;} $ calendar [] = sprintf ($ link, date ("F", $ previus_month ), date ("Y", $ previus_month), $ {$ language} ['month'] [date ("F", $ previus_month)]); $ calendar [] = EMPTY_COLUMN; $ calendar [] = EMPTY_COLUMN; $ calendar [] =$ {$ language} ['month'] [date ("F", $ start)]; $ calendar [] = EMPTY_COLUMN; $ calendar [] = EMPTY_COLUMN; $ calendar [] = sprintf ($ link, date ("F", $ next_month), date ('Y ', $ next_month), $ {$ language} ['month'] [date ('F', $ next_month)]); $ calendar [] =$ {$ language} ['week'] ['mon']; $ calendar [] =$ {$ language} ['Week '] ['tue']; $ calendar [] =$ {$ language} ['Week '] ['wed']; $ calendar [] =$ {$ language} ['week'] ['Thu']; $ calendar [] =$ {$ language} ['week'] ['Fri']; $ calendar [] =$ {$ language} ['week'] ['Sat ']; $ calendar [] =$ {$ language} ['week'] ['sun']; $ blank_td = date ("N", $ start ); for ($ I = 1; $ I <$ blank_td; $ I ++) {$ calendar [] = EMPTY_COLUMN;} $ dates = range (1, date ("t ", $ start); foreach ($ dates as $ value) {$ calendar [] = $ value;} $ cc = count ($ calendar); for ($ I = 1; $ I <= 63-$ cc; $ I ++) {$ calendar [] = EMPTY_COLUMN;} $ k = 0; $ today = date ("Y "). "". date ("F "). "". date ("j"); $ html ="
"; For ($ I = 1; $ I <= 9; $ I ++) {$ html. ="
"; For ($ j = 1; $ j <= 7; $ j ++) {if (is_int ($ calendar [$ k]) {$ cur_date = "$ year $ month $ calendar [$ k]"; if ($ cur_date = $ today) {$ html. ="
". $ Calendar [$ k ++]." | ";} Else {$ html. ="
". $ Calendar [$ k ++]." | ";}} Else {$ html. ="
". $ Calendar [$ k ++]." | ";}}$ Html. ="
";} $ Html. ='
'. Sprintf ($ link, date ('F'), date ('Y'), $ {$ language} ['Today']).' |
'; $ Html. ="
"; Return $ html;} echo" English calendar:
"; Echo php_calendar (" EN "); echo"
"; Echo" Chinese calendar:
"; Echo php_calendar (" CN ") ;?>