note 82907 added to function.strtotime

From: Date: Thu, 01 May 2008 08:40:09 +0000
Subject: note 82907 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-138964@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 217.13.201.10 Probable Submitter: 86.103.205.95 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/82907 Del: integrated -- https://master.php.net/note/delete/82907/integrated Del: useless -- https://master.php.net/note/delete/82907/useless Del: bad code -- https://master.php.net/note/delete/82907/bad+code Del: spam -- https://master.php.net/note/delete/82907/spam Del: non-english -- https://master.php.net/note/delete/82907/non-english Del: in docs -- https://master.php.net/note/delete/82907/in+docs Del: other reasons-- https://master.php.net/note/delete/82907 Reject -- https://master.php.net/note/reject/82907 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138964) next »