This article mainly introduces the calendar program implemented in PHP. Friends who are interested can refer to it. I hope it will be helpful to everyone.
The details are as follows:
<?php /* * php 输出日历程序 */ 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 "出错!"; echo "<BR>"; echo "<a href=",$curUrl,">Back</a>"; exit(); } ?> <table width="200" border="1" cellspacing="0" cellpadding="0" bordercolor="#E7E7E7" style="font-size:12px;" align="center"> <tr align="center"><td colspan="2"> <?php //<-------当月份超出1至12时的处理;开始-------> if($month<1){ $month=12; $year-=1; } if($month>12){ $month=1; $year+=1; } //<-------当月份超出1至12时的处理;结束-------> //<---------上一年,下一年,上月,下月的连接处理及输出;开始---------> echo "<a href=",$curUrl,"?year=".($year-1)."&month=".$month."><<</a>年<a href=",$curUrl,"?year=".($year+1)."&month=".$month.">>></a>"; ?> </td><td colspan="3"><?php echo $year."年".$month."月";?> </td><td colspan="2"> <?php echo "<a href=",$curUrl,"?month=".($month-1)."&year=".$year."><<</a>月<a href=",$curUrl,"?month=".($month+1)."&year=".$year.">>></a>"; //<--------上一年,下一年,上月,下月的连接处理及输出;结束---------> ?></td></tr> <tr align=center><td><font color="red">日</font></td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr><tr> <?php $d=date("d"); $FirstDay=date("w",mktime(0,0,0,$month,1,$year));//取得任何一个月的一号是星期几,用于计算一号是由表格的第几格开始 $bgtoday=date("d"); function font_color($month,$today,$year){//用于计算星期天的字体颜色 $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){//用于计算当日的背景颜色 $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){//用于计算星期天的字体风格 $sunday=date("w",mktime(0,0,0,$month,$today,$year)); if($sunday=="0"){ $FontStyle="<strong>"; }else{ $Font; } return $FontStyle; } for($i=0;$i<=$FirstDay;$i++){//此for用于输出某个月的一号位置 for($i;$i<$FirstDay;$i++){ echo "<td align=center> </td>\n"; } if($i==$FirstDay){ echo "<td align=center ".bgcolor($month,$bgtoday,1,$year)."><font color=".font_color($month,1,$year).">".font_style($month,1,$year)."1</font></td>\n"; if($FirstDay==6){//判断1号是否星期六 echo "</tr>"; } } } $countMonth=date("t",mktime(0,0,0,$month,1,$year));//某月的总天数 for($i=2;$i<=$countMonth;$i++){//输出由1号定位,随后2号直至月尾的所有号数 echo "<td align=center ".bgcolor($month,$bgtoday,$i,$year)."><font color=".font_color($month,$i,$year).">".font_style($month,$i,$year)."$i</font></td>\n"; if(date("w",mktime(0,0,0,$month,$i,$year))==6){//判断该日是否星期六 echo "</tr>\n"; } } ?> </table>
The calendar effect output by php is as follows:
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
How to generate a QR code with logo in PHP
How to implement the Model base class based on mysqli in PHP And examples
Detailed explanation of methods and examples of PHP file upload class
The above is the detailed content of Calendar program implemented in php. For more information, please follow other related articles on the PHP Chinese website!

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)
