note 32920 deleted from function.date by sniper
| From: | sniper@php.net | Date: | Sat, 11 Oct 2003 16:54:14 +0000 |
| Subject: | note 32920 deleted from function.date by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58296@lists.php.net to get a copy of this message | ||
Note Submitter: Thomas Kornack
----
Here's code that can extract the timestamp from a loosely formatted date string that a user
inputs. It can deal with 'August 3rd, 2002' or '3 August 2002; or 2002 Aug
<?php
echo ExtractTimeStamp('August 3rd, 2002');
function ExtractTimeStamp($datestr) {
$frags = explode(' ',$datestr);
foreach ($frags as $frag) {
switch (strtoupper(substr($frag,0,3))) {
case "JAN": $ex_month=1; break;
case "FEB": $ex_month=2; break;
case "MAR": $ex_month=3; break;
case "APR": $ex_month=4; break;
case "MAY": $ex_month=5; break;
case "JUN": $ex_month=6; break;
case "JUL": $ex_month=7; break;
case "AUG": $ex_month=8; break;
case "SEP": $ex_month=9; break;
case "OCT": $ex_month=10; break;
case "NOV": $ex_month=11; break;
case "DEC": $ex_month=12; break;
}
$ex_value = (int)$frag;
if ( ($ex_value > 0) and ($ex_value < 32) ) { $ex_day = $ex_value; }
if ($ex_value > 1900) { $ex_year = $ex_value; }
}
echo $ex_day,', ',$ex_month,', ',$ex_year,'<br>';
return mktime(0,0,0,$ex_month,$ex_day,$ex_year);
}
?>