Expert guidance on how to get the day of the week in PHP_PHP Tutorial

WBOY
Release: 2016-07-15 13:27:34
Original
848 people have browsed it

I have been learning PHP for a long time, and I would like to share my experience with you. PHP is a server-side scripting language used to create dynamic WEB pages. Like ASP and ColdFusion, users can use a mixture of PHP and HTML to write WEB pages. When a visitor browses to the page, the server will first process the PHP commands in the page, and then transmit the processed results together with the HTML content to Access browser.

But unlike ASP or ColdFusion, PHP is an open source program with good cross-platform compatibility. Users can run PHP on Windows NT systems and many versions of Unix systems, and can run PHP as a built-in module of the Apache server or as a CGI program. In addition to being able to precisely control the display content of WEB pages, users can also send HTTP headers by using PHP. Users can set cookies through PHP, manage user identification, and redirect users' browsing pages. PHP has very powerful database support functions and can access almost all currently popular database systems. In addition, PHP can be integrated with multiple external libraries to provide users with more practical functions, such as generating PDF files.

Users can enter PHP command codes directly on the WEB page, so no special development environment is required. In WEB pages, all PHP code is placed in "". Additionally, users can choose to use a form such as . The PHP engine will automatically identify and process all code between PHP delimiters in the page. The grammatical structure of the PHP scripting language is very similar to the grammatical style of the C language and Perl language. Users do not need to declare variables before using them. The process of creating an array using PHP is also very simple. PHP also has basic object-oriented component functions, which can greatly facilitate users to effectively organize and encapsulate the code they write. Today I will introduce to you a method to get the day of the week in PHP. I hope it will be helpful to you.

PHP day of the week code:
<ol class="dp-xml">
<li class="alt"><span><span>date("l");  </span></span></li>
<li class=""><span>//data就可以获取英文的星期比如Sunday  </span></li>
<li class="alt"><span>date("w");  </span></li>
<li class=""><span>//这个可以获取数字星期比如123,注意0是星期日 </span></li>
</ol>
Copy after login

Getting the Chinese day of the week can be done like this

<ol class="dp-xml">
<li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">weekarray</font></span><span>=array("日","一","二","三","四","五","六");  </span></span></li>
<li class=""><span>echo "星期".$weekarray[date("w")]; </span></li>
</ol>
Copy after login

Getting the specified date is:

<ol class="dp-xml">
<li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">weekarray</font></span><span>=array("日","一","二","三","四","五","六");  </span></span></li>
<li class=""><span>echo "星期".$weekarray[date("w","2011-11-11")]; </span></li>
</ol>
Copy after login

Because The date function is very powerful. It can handle all such tasks. I have attached a table in the manual

<ol class="dp-xml">
<li class="alt"><span><span>a - "am" 或是 "pm"   </span></span></li>
<li class=""><span>A - "AM" 或是 "PM"   </span></li>
<li class="alt"><span>d - 几日,二位数字,若不足二位则前面补零; 如: "01" 至 "31"   </span></li>
<li class=""><span>D - 星期几,三个英文字母; 如: "Fri"   </span></li>
<li class="alt"><span>F - 月份,英文全名; 如: "January"   </span></li>
<li class=""><span>h - 12 小时制的小时; 如: "01" 至 "12"   </span></li>
<li class="alt"><span>H - 24 小时制的小时; 如: "00" 至 "23"   </span></li>
<li class=""><span>g - 12 小时制的小时,不足二位不补零; 如: "1" 至 12"   </span></li>
<li class="alt"><span>G - 24 小时制的小时,不足二位不补零; 如: "0" 至 "23"   </span></li>
<li class=""><span>i - 分钟; 如: "00" 至 "59"   </span></li>
<li class="alt"><span>j - 几日,二位数字,若不足二位不补零; 如: "1" 至 "31"   </span></li>
<li class=""><span>l - 星期几,英文全名; 如: "Friday"   </span></li>
<li class="alt"><span>m - 月份,二位数字,若不足二位则在前面补零; 如: "01" 至 "12"   </span></li>
<li class=""><span>n - 月份,二位数字,若不足二位则不补零; 如: "1" 至 "12"   </span></li>
<li class="alt"><span>M - 月份,三个英文字母; 如: "Jan"   </span></li>
<li class=""><span>s - 秒; 如: "00" 至 "59"   </span></li>
<li class="alt"><span>S - 字尾加英文序数,二个英文字母; 如: "th","nd"   </span></li>
<li class=""><span>t - 指定月份的天数; 如: "28" 至 "31"   </span></li>
<li class="alt"><span>U - 总秒数   </span></li>
<li class=""><span>w - 数字型的星期几,如: "0" (星期日) 至 "6" (星期六)   </span></li>
<li class="alt"><span>Y - 年,四位数字; 如: "1999"   </span></li>
<li class=""><span>y - 年,二位数字; 如: "99"   </span></li>
<li class="alt"><span>z - 一年中的第几天; 如: "0" 至 "365" </span></li>
</ol>
Copy after login

The above introduces in detail the method of getting the day of the week in PHP and the introduction of the date function. Come on, everyone. Give it a try.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446519.htmlTechArticleI have been learning PHP for a long time, and I would like to share my experience with you. PHP is a server-side scripting language used to create dynamic WEB pages. Like ASP and ColdFusion, users can mix...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!