PHP Simple calendar function, PHP calendar _php Tutorial

Source: Internet
Author: User
Tags learn php learn php programming

PHP Simple calendar function, PHP calendar


This article is an example of a PHP implementation of the calendar program. Share to everyone for your reference. Specific as follows:

<?php/* * PHP Output Calendar program */Header ("Content-type:text/html;charset=utf-8"); $year = (!isset ($_get[' year ') | | $_get[' year ']== "")? Date ("Y"): $_get[' year ']; $month = (!isset ($_get[' month ') | | $_get[' month ']== "")? Date ("N"): $_get[' month '];  $curUrl =$_server[' php_self '];   if ($year <1971) {echo "Error!"; echo "
"; echo "Back"; Exit (); }?>"; }else{$FontStyle = ""; } return $FontStyle; } for ($i =0; $i <= $FirstDay; $i + +) {//This for is used to output one position of a month for ($i; $i < $FirstDay; $i + +) {echo "\ n "; if ($i = = $FirstDay) {echo '\ n "; if ($FirstDay ==6) {//Determine if number 1th is Saturday echo ""; }}} $countMonth =date ("T", Mktime (0,0,0, $month, 1, $year));//The total number of days of the month for ($i =2; $i <= $countMonth; $i + +) {//output is positioned by number 1th, Then the number 2nd until the month of the month Echo "\ n "; if (Date ("W", Mktime (0,0,0, $month, $i, $year)) ==6) {//Determine if the day is Saturday echo "\ n "; }}?> <?php $d =date ("D"), $FirstDay =date ("W", Mktime (0,0,0, $month, 1, $year));//Get any one months of a number is the day of the week, used to calculate the number of the table starting from the first $ Bgtoday=date ("D"); function Font_color ($month, $today, $year) {//used to calculate the font color for Sunday $sunday =date ("W", Mktime (0,0,0, $month, $today, $year)); if ($sunday = = "0") {$FontColor = "red"; }else{$FontColor = "BLACK"; } return $FontColor; } function bgcolor ($month, $bgtoday, $today _i, $year) {//for calculating the background color of the day $show _today=date ("D", Mktime (0,0,0, $month, $today _ I, $year)); $sys _today=date ("D", Mktime (0,0,0, $month, $bgtoday, $year)); if ($show _today== $sys _today) {$bgcolor = "bgcolor= #6699FF"; }else{$bgcolor = ""; } return $bgcolor; } function Font_style ($month, $today, $year) {//for calculating Sunday font style $sunday =date ("W", Mktime (0,0,0, $month, $today, $year)); if ($sunday = = "0") {$FontStyle = "
<?php//<-------The processing of the month exceeding 1 to 12 o'clock; start-------> if ($month <1) {$month = 12; $year-=1; } if ($month >12) {$month = 1; $year +=1; }//<-------The processing of the month exceeding 1 to 12 o'clock; end------->//<---------last year, next year, last month, connection processing and output of the following months; start---------> Echo < <年> > ";?> <?php echo $year. " Year ". $month." Month ";? > <?php echo "< <月> >";//<--------last year, next year, last month, next month's connection processing and output; end--------->?>
Day One Two Three Four Five Six
" . Font_style ($month, 1, $year). " 1
". Font_style ($month, $i, $year)." $i

The PHP output calendar effect is as follows:

I hope this article is helpful for you to learn PHP programming.

http://www.bkjia.com/PHPjc/1065567.html www.bkjia.com true http://www.bkjia.com/PHPjc/1065567.html techarticle PHP Simple calendar function, PHP Calendar This example describes the implementation of the PHP calendar program. Share to everyone for your reference. The following: PHP/* * PHP Output Calendar program */Header ("Conten ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.