note 30853 rejected from function.checkdate by nicos
| From: | nicos@php.net | Date: | Tue, 01 Apr 2003 14:01:35 +0000 |
| Subject: | note 30853 rejected from function.checkdate by nicos | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-46077@lists.php.net to get a copy of this message | ||
For European users, I suggest the following wrapper function to seamlessly utilize checkdate() with
dates in format "dd/mm/yyyy" (note: echo() in the function body they're used just for
test and can be deleted):
<?php
function valida_data($date){
// la funzione explode effettua il parsing della data
// trasformandola in un array di tre elementi
// nel primo c'è il giorno, nel secondo il mese,
// nel terzo l'anno
$array_date = explode("/", $date);
echo "Giorno: ".$array_date[0]."<br>";
echo "Mese: ".$array_date[1]."<br>";
echo "Anno: ".$array_date[2]."<br>";
echo "<br>";
// verifica della liceità della data tramite checkdate
if (checkdate($array_date[1], $array_date[0], $array_date[2])){
return true;
} else {
return false;
}
}
// data da testare
$date = "18/16/2003";
if (valida_data($date)){
echo "$date è una data corretta\n";
} else {
echo "$date non è una data corretta\n";
}
?>