Ken Tozier wrote:
Hi
I wrote a serialization function to turn arbitrary PHP variables into
Macintosh plist compatible XML but see that there is no "is_date" tester
as there is for bool, object, array etc. Is there a relatively simple
(and robust) way to detect if a variable is a date? For example:
$person = array('name'=>'bob', 'sex'=>'male', 'date_of_birth'=>
$someDateHere);
Thanks for any help
Ken
--PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Here is my suggestion. You COULD use strtotime() and try and have PHP see if it recognizes the
input string as a date time stamp or something.
Live example
http://www.cmsws.com/examples/php/is_date.php
source
<pre><?php
function is_date($in) {
return (boolean) strtotime($in);
}
$dates = array(
'tomorrow',
'yesterday',
'next week',
'last year',
'April 1st',
'December 23, 1999 4pm',
);
foreach ( $dates AS $row ) {
echo "Time is: ".date('c', strtotime($row));
echo " {$row} is ";
var_dump(is_date($row));
}
?>
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php