Re: Clean break.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Paul Halliday wrote:
> Whats the cleanest (I have a really ugly) way to break this:
> 
> [21/Jul/2009:00:00:47 -0300]
> 
> into:
> 
> date=21/jul/2009
> time=00:00:47
> 
> Caveats:
> 
> 1) if the day is < 10 the beginning of the string will look like "[<space>1/...
> 2) the "-0300" will differ depending on DST or TZ. I don't need it
> though, it just happens to be there.
> 
> This is what I have (it works unless day < 10):
> 
> $theParts = split("[\"]", $theCLF);
> 
>         // IP and date/time
>         $tmpParts = explode(" ", $theParts[0]);
>         $theIP = $tmpParts[0];
>         $x = explode(":", $tmpParts[3]);
>         $theDate = str_replace("[","", $x[0]);
>         $theTime = "$x[1]:$x[2]:$x[3]";
> 
> the full text for this part looks like:
> 
> 10.0.0.1 - - [21/Jul/2009:00:00:47 -0300] ... more stuff here
> 
> Anyway, any help would be appreciated.
> 
> thanks.


As far as I can tell from a brief test, date_create will happily parse your
format, so something like

$tmp = date_create($theParts[0]);
$theDate = $tmp->format("d/m/Y");
$theTime = $tmp->format("h:i:s");

should do it


-- 
Peter Ford                              phone: 01580 893333
Developer                               fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux