Stefan - 31. März 2008
I just wasted about an hour of my working time looking for an error in my code. I tried to use the built-in strtotime() function to convert a date string from a log file to the appropriate timestamp:
The date string looks like this:
Using phpa, the command line PHP tool, I got what I expected:
PHP 5.2.0 (cli) (???) [Darwin]
>>> print strtotime("1/Jan/2007:08:03:50 +0100");
But in my PHP script, the very same command returns -1. After a lot of experiments, I found the problem. While my phpa tool uses PHP5, the script is invoked via php – which defaults to PHP 4.4.7. Obviously, the date format used in log files was added to strtotime() in PHP5:
macbook:~ sf$ php -r 'print phpversion()."n"; print strtotime("01/Jan/2007:08:03:50 +0100")."n";'
macbook:~ sf$ php5 -r 'print phpversion()."n"; print strtotime("01/Jan/2007:08:03:50 +0100")."n";'
So, be sure to check what PHP version you’re running, if you get into trouble with strtotime().