Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP上使用RegExp验证unix时间?_Php_Regex_Validation_Preg Match - Fatal编程技术网

如何在PHP上使用RegExp验证unix时间?

如何在PHP上使用RegExp验证unix时间?,php,regex,validation,preg-match,Php,Regex,Validation,Preg Match,可能重复: 我需要在php上用regexp验证unix时间。 例如: 谢谢;) 那么: function is_unix($t) { if ( is_numeric($t) && 0<$t && $t<strtotime("some date in the future that you don't expect the value to exceed, but before year 2038") ) { return

可能重复:

我需要在php上用regexp验证unix时间。 例如:


谢谢;)

那么:

function is_unix($t) {
    if ( is_numeric($t) && 0<$t && $t<strtotime("some date in the future that you don't expect the value to exceed, but before year 2038") ) {
        return true;
    }else{
        return false;
}
函数是unix($t){

if(is numeric($t)&&0零和
time()
产生的任何数字之间的任何数字都是有效的。您的正则表达式只检查变量中是否至少有一个数字出现。要检查整个值,您可以使用
/^\d+$/
(确保它从字符串开始检查到结束)或者将该值转换为一个int,然后检查两者是否相等:
(int)$unix==$unix
替换
您不希望该值超过的某个日期?@Mark:谢谢,我在中添加了该位。
function is_unix($t) {
    if ( is_numeric($t) && 0<$t && $t<strtotime("some date in the future that you don't expect the value to exceed, but before year 2038") ) {
        return true;
    }else{
        return false;
}