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

php gets what day of the week today is

王林
王林Original
2019-09-27 11:58:116379browse

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 "你输入有误!!";
};

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 "你输入有误!";
};

The third way of writing:

Function:mb_substr()

Syntax:

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

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" );

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!

Statement:
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