note 82907 deleted from function.strtotime by derick
| From: | derick@php.net | Date: | Sun, 03 Aug 2008 11:54:24 +0000 |
| Subject: | note 82907 deleted from function.strtotime by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-143111@lists.php.net to get a copy of this message | ||
Note Submitter: till at pralinenschachtel dot de
----
In some versions strtotime() can't handle time offsets like: +1000, UTC, WET, UTC+0, ...
<?php
print strtotime('Thu Apr 03 18:26:36 +0000 2008'); // PHP 4.4.4: -1
print strtotime('Thu Apr 03 18:26:36 +0000 2008'); // PHP 5.2.5: 1207247196
?>
I made the following function to get always the correct timestamp. Just adjust the str_replace() to
your timestamp pattern.
<?php
function str2time($string) {
$time = strtotime($string);
if (!$time) {
$offset = date('Z');
$string = str_replace('+0000', '', $string);
if ($offset > 0) {
print strtotime($string) + $offset;
} else {
print strtotime($string) - $offset;
}
}
return $time;
}
?>