Php calendar code efficient calendar code implemented by php
/*
- * Php calendar
- * Edit: bbs.it-home.org
- */
- @ Date_default_timezone_set ('rpc ');
Function show_calender (){
- $ Starttime = microtime ();
// Request processing date
- $ Y = isset ($ _ GET ["y"])? Intval ($ _ GET ["y"]): date ("Y ");
- $ M = isset ($ _ GET ["m"])? Intval ($ _ GET ["m"]): date ("m ");
- If ($ m <1 | $ m> 12) $ m = date ("m ");
- If ($ y <= 0) $ y = date ("Y ");
// Next month
- $ Nm = $ m + 1;
- If ($ nm> 12 ){
- $ Nm = 1;
- $ Ny = $ y + 1;
- } Else {
- $ Ny = $ y;
- }
// January 1, January
- $ Pm = M-1;
- If ($ pm <1 ){
- $ Pm = 12;
- $ Py = $ Y-1;
- } Else {
- $ Py = $ y;
- }
// Obtain the name of this month
- $ Month = date ("M", mktime (0, 0, 0, $ m, 1, $ y ));
// Obtain the last day of the month
- $ Lastday = date ("d", mktime (0, 0, 0, $ nm, 0, $ ny ));
// Obtain the day of the week from the start day
- $ Index = date ("w", mktime (0, 0, 0, $ m, 1, $ y ));
// Generate the calendar header
- Echo"
// Process calendar
- If ($ row = 0 ){
- Else
- } Else {
- Else
- }
- $ Row ++;
- $ Row = 0;
- $ Day = 1;
- While (1 ){
- Echo"
- For ($ I = 0; $ I <= 6; $ I ++)
- If ($ I <$ index)
- Echo"
- Echo"
- For ($ I = 0; $ I <= 6; $ I ++)
- If ($ day> $ lastday)
- Echo"
- Echo"
- Echo"
- If ($ day> $ lastday) break;
- }
- Echo"
\ N
- |
{$ Y} {$ month} |
+ |
\ N
Day |
I |
II |
3. |
Thu |
V. |
Sat. |
";
";
| ";
". $ Day ++ ." | ";
| ";
". $ Day ++ ." | ";
";
";
$ Endtime = microtime ();
- $ Usedtime = $ endtime-$ starttime;
- Return $ usedtime;
- }
$ Run_info = array ();
- For ($ I = 0; $ I <10; $ I ++)
- $ Run_info [] = show_calender ();
Print_r ($ run_info );
- ?>
Test results: Array ([0] => 0.00038400000000005 [1] => 0.00030999999999998 [2] => 0.00029699999999999 [3] => 0.000303 [4] => 0.00030399999999997 [5] => 0.00034499999999998 [6] => 0.00032300000000002 [7] => 0.00033 [8] => 0.00032699999999997 [9] => 0.00032000000000004)>>> Articles you may be interested in: php calender calendar code (solving 2038 issues) php calendar code (with demo effect) php calendar code sharing simple and practical php calendar code three good php calendar code sharing a PHP simple calendar code php simple calendar implementation code (events can be bound) |