PHP exercises and PHP exercises _ PHP tutorials

Source: Internet
Author: User
PHP exercises and PHP exercises. PHP exercises, PHP exercises a few days ago in Baidu know that a netizen asked how to make a small program: design a small program in php language, calculate the PHP exercises that arrive next month today, PHP exercise questions

A few days ago, I saw a netizen asking how to create a small program in Baidu:Design a small program in php, calculate the number of days that have arrived in the next month, and output all these days. then, display the date in three colors and set three forms, let the user select the font color, and then cyclically output the three colors to reflect the dates of the output.. Today, we have just made time for him. this is actually of no practical use, but new friends can use it as a small PHP practice project, use it to familiarize yourself with or deepen your understanding of PHP!

At that time, I gave him the following general idea:

1. calculate the number of days from today to next month. you can use two arrays, one array, and the other array, to access the last 30 days of the month, this can be carefully studied by yourself. the above is just an example )! Then, obtain the month of the current day. in which array is displayed, determine the total number of days of the current month. then, you can output all the days from the current day to the end of the month!

2. let the user select three font colors. I think a form is enough. use checkbox to select the three colors you like!

3. three colors are output cyclically. I think so!

123456789 // $ Color is an array that stores three colors// $ Date is the array that stores all days$i = 0;$content = '';foreach ($date as $value) { $content .= '.$color[$i].'">'.$value.''; $i ++; if ($i > 2) $i = 0;}

In this way, $ content contains all the days and color styles!

Below are the specific code of the above PHP small exercise project compiled by myself. you can check it out. please correct me if it is not correct!

First part of the HTML code allows users to select their own colors (not specified)

12345678 <form method="post"> <input type="checkbox" value="red" name="color[]"/> Red <input type="checkbox" value="black" name="color[]"/> Black <input type="checkbox" value="blue" name="color[]"/> Blue <input type="checkbox" value="yellow" name="color[]"/> Yellow <input type="checkbox" value="green" name="color[]"/> Green <input type="submit" value="Submit" name="send"/> form>

Then the PHP background code

12345678910111213141516171819202122232425262728293031 if (isset($_POST['send'])) { // Obtain the color $color = $_POST['color']; // Calculates the number of days $date = date('Y-m-d', time()); $dates = explode('-', $date); $sy = array('1','3','5','7','8','10','12'); $ss = array('4','6','9','11'); // Judge if (in_array($dates[1], $sy)) { $day = range($dates[2], 31); } elseif (in_array($dates[1], $ss)) { $day = range($dates[2], 30); } else { if (($dates[0]%4 == 0 && $dates[0]%100 != 0) || ($dates[0]%100 == 0 && $dates[0]%400 == 0)) { $day = range($dates[2], 29); } else { $day = range($dates[2], 28); } } // Combine the days and colors $i = 0; $content = ''; foreach ($day as $value) { $content .= '.$color[$i].'">'.$value.' '; $i ++; if ($i > (count($color)-1)) $i = 0; } echo $content;

In this way, $ content can output the desired effect!

Do you want to get updates from Wang yelou's personal blog every day? Add the public account"Ly89cn", Or scan the QR code below!

This article from Wang yelou's personal blog, this article address: http://www.ly89.cn/detailB/64.html

You are welcome to share this article. For more information, see the source and address of this article.

Baidu saw a netizen asking how to create a small program in Baidu's knowledge a few days ago: design a small program in php and calculate the next month's arrival today...

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.