Home > Backend Development > PHP Tutorial > 怎样校验输入的日期为合法的日期?这里有一个例子(checkdate.php3_PHP

怎样校验输入的日期为合法的日期?这里有一个例子(checkdate.php3_PHP

WBOY
Release: 2016-06-01 12:28:39
Original
840 people have browsed it



function is_numeric($var){
   $str = (string)$var;
   $int = (int)$var;
   $strstr = (string)$int;
   if($strstr==$str) return true;
   else return false;
}

function check($year,$month,$day)
{
   if(is_numeric($year) and is_numeric($month) and is_numeric($day)){
      if(checkdate($month,$day,$year)){
         echo $year . "年" . $month . "月" . $day . "日 是合法日期!
";
      }
      else{
         echo $year . "年" . $month . "月" . $day . "日 不是合法日期!
";
      }
   }
   else{
      echo $year . "年" . $month . "月" . $day . "日 不是合法日期!
";
   }
}

check("1999","1","1");
check("2000","2","31");
check("1900","2","1");
check("1900.2","2","1");
check("aaa","1","1");
?>

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