<?
$x = array("20040301", "20041301", "20040341", "21040301", "18040301", "19040301");
$y = 0;
while ($y <= count($x)) {
echo $x[$y];
if (!ereg("\d{8}", $x[$y])) echo " is BAD<br>"; // "^(19|20)\d{2}(0|1)\d(0-3)\d$"
else echo " is GOOD<br>";
$y++;
}
?>
echo time();
echo "
";
$x = array("20040301", "20041301", "20040341", "21040301","20042301", "18040301", "19040301", "200403012", "2004030", "20040230", "20040229");
$y = 0;
while ($y < count($x)) {
switch ($x[$y]) {
case !preg_match("/^(19|20)\d{2}(0|1)\d{1}[0-3]\d{1}$/", $x[$y]):
echo $x[$y]." is BAD
";
break;
case strtotime($x[$y])=== -1:
echo $x[$y]." (".date("Y-m-d", strtotime($x[$y])).") is WRONG
";// "^(19|20)\d{2}(0|1)\d(0-3)\d$"
break;
default:
echo $x[$y]." is GOOD
";
}
$y++;
echo "
";
}
?>