Home > Backend Development > PHP Tutorial > PHP checks whether it is a legal time format regular_PHP tutorial

PHP checks whether it is a legal time format regular_PHP tutorial

WBOY
Release: 2016-07-13 17:14:33
Original
1137 people have browsed it

The following summarizes several ways to use php to verify whether the date entered by the user is the correct date. Friends in need can refer to it.

The checkdate() function verifies a Gregorian date.

Example

/**
The code is as follows
 代码如下 复制代码

var_dump(checkdate(12,31,2000));
var_dump(checkdate(2,29,2003));
var_dump(checkdate(2,29,2004));
?>输出:

bool(true)
bool(false)
bool(true)

Copy code

var_dump(checkdate(12,31,2000));
var_dump(checkdate(2,29,2003));
var_dump(checkdate(2,29,2004));
?>Output:

bool(true)
bool(false)
bool(true)

 代码如下 复制代码

* 检查是否为一个合法的时间格式
*
* @param string $time
* @return void
*/
function is_time($time)
{
$pattern = '/[d]{4}-[d]{1,2}-[d]{1,2}s[d]{1,2}:[d]{1,2}:[d]{1,2}/';

return preg_match($pattern, $time);
}

Regular date

 代码如下 复制代码

$reg="/d{4}-d{2}-d{2}/";
preg_match($reg,$days,$arr);
print_r($arr);

Example 1
The code is as follows Copy code

return preg_match($pattern, $time);
}
Example 2 Regular verification date
The code is as follows Copy code
$reg="/d{4}-d{2}-d{2}/";
preg_match($reg,$days,$arr);
print_r($arr);
http://www.bkjia.com/PHPjc/628963.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628963.htmlTechArticleThe following summarizes several ways to use php to verify whether the date entered by the user is the correct date. Friends in need Can be used for reference. The checkdate() function verifies a Gregorian date. Example...
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