PHP Example————Perpetual Calendar_PHP Tutorial
PHP Example————Perpetual Calendar
Share with you a simple perpetual calendar production process.
Basic requirements:
1. Obtain date
2. Get the date of a given date
3. Get the day of the week for a given date
4. Get the number of days in the month
5. Get the previous month and next month
Post a rendering first, the style is rather ugly, don’t spray it if you don’t like it.
php code:
<?php //修改字符编码 header("content-type:text/html;charset=utf-8"); //外部样式链接 echo "<link rel='stylesheet' type='text/css' href='calendar.css'/>"; //获取当前年 $year=$_GET['Y']?$_GET['Y']:date('Y'); //获取当前月 $month=$_GET['m']?$_GET['m']:date('m'); //获取当月有多少天 $days=date('t',strtotime("{$year}-{$month}-1")); //当前是周几 $week=date('w',strtotime("{$year}-{$month}-1")); //内容居中显示 echo "<center>"; //打印表头 echo "<h1 id="year-年-month-月">{$year}年{$month}月</h1>"; //打印日期表格 echo "<table>"; //打印星期 echo "<tr>"; echo "<th>周日</th>"; echo "<th>周一</th>"; echo "<th>周二</th>"; echo "<th>周三</th>"; echo "<th>周四</th>"; echo "<th>周五</th>"; echo "<th>周六</th>"; echo "</tr>"; //打印几号 for($i=1-$week;$i<=$days;){ echo "<tr>"; for($j=0;$j<7;$j++){ if($i>$days||$i<1){ echo "<td> </td>"; }else{ echo "<td>$i</td>"; } $i++; } echo "</tr>"; } echo "</table>"; //上一月和下一月算法 if($month==1){ $prevyear=$year-1; $prevmonth=12; }else{ $prevyear=$year; $prevmonth=$month-1; } if($month==12){ $nextyear=$year+1; $nextmonth=1; }else{ $nextyear=$year; $nextmonth=$month+1; } //上一月和下一月的超链接 echo "<h2 id="上一月-amp-下一月">上一月&下一月</h2>"; echo "</center>"; ?>
CSS code:
table{ width:500px; height:300px; border:red dashed 1px; background:#ff00ff; } tr{ text-align:center; } td{ border:gray dotted 1px; } h1{ font-style:italic; font-size:50px; font-family:'宋体'; } h2 a{ font-style:normal; font-size:40px; font-family:'黑体'; color:purple; } /*组合选择器*/ tr,td,th{ font-size:20px; background:gray; }
Let’s talk about some common mistakes and clever usage:
1. The timestamp calculated in strtotime() should be in a complete format. It is useless to put a separate year or month in it.
2. The condition in the if statement is not assignment, but equal! ! ! , you need to write two ==. This place is so easily overlooked.
3. The originally printed date always corresponds to Sunday and the 1st. However, if the month is different, the corresponding relationship between the date and the week will also change. Therefore, by changing $i-$week. in the for loop, all the dates of the current month can be moved back a certain time to achieve a perfect correspondence between the date and the week.
4. When implementing the functions of the previous month and the next month, bring in several variables as parameters, and then cooperate with a certain algorithm to get it done. Specifically, just look at the code. No matter how good the text is, it is not as effective as reading two lines of code.

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



Support Vector Machine (SVM) in Python is a powerful supervised learning algorithm that can be used to solve classification and regression problems. SVM performs well when dealing with high-dimensional data and non-linear problems, and is widely used in data mining, image classification, text classification, bioinformatics and other fields. In this article, we will introduce an example of using SVM for classification in Python. We will use the SVM model from the scikit-learn library

As the new generation of front-end frameworks continues to emerge, VUE3 is loved as a fast, flexible, and easy-to-use front-end framework. Next, let's learn the basics of VUE3 and make a simple video player. 1. Install VUE3 First, we need to install VUE3 locally. Open the command line tool and execute the following command: npminstallvue@next Then, create a new HTML file and introduce VUE3: <!doctypehtml>

Golang is a powerful and efficient programming language that can be used to develop various applications and services. In Golang, pointers are a very important concept, which can help us operate data more flexibly and efficiently. Pointer conversion refers to the process of pointer operations between different types. This article will use specific examples to learn the best practices of pointer conversion in Golang. 1. Basic concepts In Golang, each variable has an address, and the address is the location of the variable in memory.

VAE is a generative model, its full name is VariationalAutoencoder, which is translated into Chinese as variational autoencoder. It is an unsupervised learning algorithm that can be used to generate new data, such as images, audio, text, etc. Compared with ordinary autoencoders, VAEs are more flexible and powerful and can generate more complex and realistic data. Python is one of the most widely used programming languages and one of the main tools for deep learning. In Python, there are many excellent machine learning and deep

The relationship between the number of Oracle instances and database performance Oracle database is one of the well-known relational database management systems in the industry and is widely used in enterprise-level data storage and management. In Oracle database, instance is a very important concept. Instance refers to the running environment of Oracle database in memory. Each instance has an independent memory structure and background process, which is used to process user requests and manage database operations. The number of instances has an important impact on the performance and stability of Oracle database.

With the rapid development of the Internet, data has become one of the most important resources in today's information age. As a technology that automatically obtains and processes network data, web crawlers are attracting more and more attention and application. This article will introduce how to use PHP to develop a simple web crawler and realize the function of automatically obtaining network data. 1. Overview of Web Crawler Web crawler is a technology that automatically obtains and processes network resources. Its main working process is to simulate browser behavior, automatically access specified URL addresses and extract all information.

With the popularity of the Internet, verification codes have become a necessary process for login, registration, password retrieval and other operations. In the Gin framework, implementing the verification code function has become extremely simple. This article will introduce how to use a third-party library to implement the verification code function in the Gin framework, and provide sample code for readers' reference. 1. Install dependent libraries Before using the verification code, we need to install a third-party library goCaptcha. To install goCaptcha, you can use the goget command: $goget-ugithub

Generative Adversarial Networks (GAN) is a deep learning algorithm that uses two neural networks to compete with each other to generate new data. GAN is widely used for generation tasks in image, audio, text and other fields. In this article, we will use Python to write an example of a GAN algorithm for generating images of handwritten digits. Dataset Preparation We will use the MNIST data set as our training data set. The MNIST data set contains
