PHPRO.ORG

This little snippet gets an apache log date and returns it in the form of Sun, 17 Dec 06 03:26:49 -0500


<?php
// Set the default timezone to US/Eastern time:
date_default_timezone_set('US/Eastern');

// Simulate reading an Apache log file, with the following line:
$logline '127.0.0.1 - - [17/dec/2006:00:26:49 -0800] "GET / HTTP/1.1" 200 41228';

// Since we only want the date section, use regex to obtain it:
preg_match('/\[(.*?)\]/'$logline$matches);

// Take the date, and convert it:
$timestamp strtotime($matches[1]);

// Now echo it out again to ensure that we read it correctly:
echo date(DATE_RFC822$timestamp);
?>