Home > Backend Development > PHP Tutorial > php gets what day of the week today is

php gets what day of the week today is

王林
Release: 2023-04-07 13:28:02
Original
6418 people have browsed it

php gets what day of the week today is

##The first way of writing:

$da = date("w");
if( $da == "1" ){
echo "今天是星期一";
}else if( $da == "2" ){
echo "今天是星期二";
}else if( $da == "3" ){
echo "今天是星期三";
}else if( $da == "4" ){
echo "今天是星期四";
}else if( $da == "5" ){
echo "今天是星期五";
}else if( $da == "6" ){
echo "今天是星期六";
}else if( $da == "0" ){
echo "今天是星期日";
}else{
echo "你输入有误!!";
};
Copy after login

The second way of writing:

$ga = date("w");
switch( $ga ){
case 1 : echo "今天是星期一";break;
case 2 : echo "今天是星期二";break;
case 3 : echo "今天是星期三";break;
case 4 : echo "今天是星期四";break;
case 5 : echo "今天是星期五";break;
case 6 : echo "今天是星期六";break;
case 0 : echo "今天是星期日";break;
default : echo "你输入有误!";
};
Copy after login

The third way of writing:

Function:mb_substr()

Syntax:

mb_substr ( string $str , int $start [, int $length = NULL [, string $encoding = mb_internal_encoding() ]] ) : string
Copy after login

Note:

mb_substr() function returns a part of the string. If you want to split Chinese text, use gamb_substr(). If the start parameter is negative and length is less than or equal to start, length is 0.

echo "今天是星期" . mb_substr( "日一二三四五六",date("w"),1,"utf-8" );
Copy after login

Recommended tutorial:

PHP video tutorial

The above is the detailed content of php gets what day of the week today is. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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