strtotime() 不 return 假

strtotime() doesn't return false

当我提供仅包含 space 或任何其他字符的字符串时,

strtotime(" ") 不会 return false。

是否有任何更少的代码解决方案使其 return 错误?

我无法使用 preg_match,因为日期格式因每个用户的语言环境而异。

http://php.net/manual/en/function.strtotime.php

Returns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0, this function would return -1 on failure.

编辑:我需要验证日期字符串,而不是 trim spaces 或其他用户提供的字符。

应用 trim() 作为解决方法,在调用 strtotime().

之前删除前导和尾随空格

strtotime(' ') returns 当前时间。

strtotime('') (strtotime(trim(' '))) returns false.

函数的这种行为已经 reported as a bug and has a fix 基于修整,但看起来由于某种原因补丁尚未被 PHP 团队接受。

我错过了什么吗?您是否尝试删除 space?是否有充分的理由保留 space?当不存在 space 时,我得到 false。

strtotime("")