note 13405 deleted from function.date by jimw
| From: | jimw@php.net | Date: | Fri, 02 Nov 2001 01:09:57 +0000 |
| Subject: | note 13405 deleted from function.date by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-20085@lists.php.net to get a copy of this message | ||
Here is a quick function to parse RFC 822 formatted date strings, and to return the date, time, and
zone as 3 separate array items:
function parse_rfc822_date($datestr) {
$month_array = array('Jan'=>'01',
'Feb'=>'02',
'Mar'=>'03',
'Apr'=>'04',
'May'=>'05',
'Jun'=>'06',
'Jul'=>'07',
'Aug'=>'08',
'Sep'=>'09',
'Oct'=>'10',
'Nov'=>'11',
'Dec'=>'12');
if (eregi('[A-Z][a-z][a-z], ([0-9][0-9]?) ([A-Z][a-z][a-z]) ([0-9]{2,4})
([0-9]{2}:[0-9]{2}(:[0-9]{2})?) ([A-Z]{1,3}|[+\-][0-9]{4})',$datestr,$regs)) {
$day = $regs[1];
$monthtext = $regs[2];
$year = $regs[3];
// for 2-digit years, add 1900 if between 12 and 99, else make it year 2000+
if ($year < 12) { $year += 2000; }
if ($year > 12 && $year < 100) { $year += 1900; }
$time = $regs[4];
// $regs5 is the optional seconds part of the time
$zone = $regs[6];
$month = $month_array["$monthtext"];
$datevar = date('Y-m-d', mktime(0,0,0,$month,$day,$year));
$result['date'] = $datevar;
$result['time'] = $time;
$result['zone'] = $zone;
return $result;
}
}