{"id":479,"date":"2009-08-28T10:55:46","date_gmt":"2009-08-28T09:55:46","guid":{"rendered":"http:\/\/www.dotmana.com\/index.php\/?p=479"},"modified":"2009-08-28T10:55:46","modified_gmt":"2009-08-28T09:55:46","slug":"tolerant-php-strtotime","status":"publish","type":"post","link":"https:\/\/www.dotmana.com\/weblog\/2009\/08\/tolerant-php-strtotime\/","title":{"rendered":"tolerant php strtotime"},"content":{"rendered":"<p>If you want to enlarge strtotime php function to be tolerant about funny date (especially in mail header), here is a little function :<\/p>\n<blockquote><p>function strtotime_tolerant($time)<br \/>\n{<br \/>\n$datetime_header = strtotime($time) ;<br \/>\nif ($datetime_header === false)<br \/>\n{<br \/>\nif (preg_match(&#8216;\/(Wen, .*)\/&#8217;, $time))<br \/>\n{<br \/>\n$time = (preg_replace(&#8216;\/(Wen,) (.*)\/&#8217;, &#8216;Wed, ${2}&#8217;, $time));<br \/>\n}<br \/>\nif (preg_match(&#8216;\/(Sut, .*)\/&#8217;, $time))<br \/>\n{<br \/>\n$time = (preg_replace(&#8216;\/(Sut,) (.*)\/&#8217;, &#8216;Sat, ${2}&#8217;, $time));<br \/>\n}<br \/>\nif (preg_match(&#8216;\/(Tues, .*)\/&#8217;, $time))<br \/>\n{<br \/>\n$time = (preg_replace(&#8216;\/(Tues,) (.*)\/&#8217;, &#8216;Tue, ${2}&#8217;, $time));<br \/>\n}<br \/>\nif (preg_match(&#8216;\/(.* \\d\\d:\\d\\d:\\d\\d) (.\\d{4})\/&#8217;, $time, $matches))<br \/>\n{<br \/>\n$time = $matches[1].&#8217; &#8216;.$matches[2];<br \/>\n}<\/p>\n<p>if (preg_match(&#8216;\/(.* \\d\\d:\\d\\d:\\d\\d) (\\d{4})\/&#8217;, $time))<br \/>\n{<br \/>\n$preg_time = (preg_replace(&#8216;\/(.* \\d\\d:\\d\\d:\\d\\d) (\\d{4})\/&#8217;, &#8216;${1} +${2}&#8217;, $time));<br \/>\n}<br \/>\nif (preg_match(&#8216;\/(.* \\d\\d:\\d\\d:\\d\\d) (UT)$\/&#8217;, $time))<br \/>\n{<br \/>\n$preg_time = (preg_replace(&#8216;\/(.* \\d\\d:\\d\\d:\\d\\d) (UT)$\/&#8217;, &#8216;${1} ${2}C&#8217;, $time));<br \/>\n}<br \/>\nif (preg_match(&#8216;\/(.* \\d\\d:\\d\\d:\\d\\d) (CEDT)$\/&#8217;, $time))<br \/>\n{<br \/>\n$preg_time = (preg_replace(&#8216;\/(.* \\d\\d:\\d\\d:\\d\\d) (CEDT)$\/&#8217;, &#8216;${1} +0200&#8217;, $time));<br \/>\n}<br \/>\nif (preg_match(&#8216;\/(.* \\d\\d:\\d\\d:\\d\\d) (.0060)\/&#8217;, $time))<br \/>\n{<br \/>\n$preg_time = (preg_replace(&#8216;\/(.* \\d\\d:\\d\\d:\\d\\d) (.0060)\/&#8217;, &#8216;${1} +0100&#8217;, $time));<br \/>\n}<\/p>\n<p>if(isset($preg_time))<br \/>\n{<br \/>\n$time = $preg_time;<br \/>\n}<br \/>\n}<\/p>\n<p>return strtotime($time);<br \/>\n}<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>If you want to enlarge strtotime php function to be tolerant about funny date (especially in mail header), here is a little function : function strtotime_tolerant($time) { $datetime_header = strtotime($time) ; if ($datetime_header === false) { if (preg_match(&#8216;\/(Wen, .*)\/&#8217;, $time)) &hellip; <a href=\"https:\/\/www.dotmana.com\/weblog\/2009\/08\/tolerant-php-strtotime\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-479","post","type-post","status-publish","format-standard","hentry","category-dev"],"_links":{"self":[{"href":"https:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/posts\/479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/comments?post=479"}],"version-history":[{"count":1,"href":"https:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/posts\/479\/revisions"}],"predecessor-version":[{"id":480,"href":"https:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/posts\/479\/revisions\/480"}],"wp:attachment":[{"href":"https:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/media?parent=479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/categories?post=479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/tags?post=479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}