Jesper Posted March 13, 2009 Share Posted March 13, 2009 Hey everyone, While I was working on an RSS script, I ran into a problem. How can I turn the pubDate from RSS feeds (format: "Fri, 13 Mar 2009 11:40:02 +0000") into a time (like mktime() does). I've tried strtotime() already but it didn't working, and I was wondering if there was an efficient way. Thanks in advance, Jesper Link to comment https://forums.phpfreaks.com/topic/149228-rss-pubdate-to-time/ Share on other sites More sharing options...
Jesper Posted March 14, 2009 Author Share Posted March 14, 2009 Does nobody have experience with this problem or does anyone else have a solution? Link to comment https://forums.phpfreaks.com/topic/149228-rss-pubdate-to-time/#findComment-784468 Share on other sites More sharing options...
BillyBoB Posted March 14, 2009 Share Posted March 14, 2009 You are going to have to build a whole new function for this one. Something like: <?php function pub2stamp($pubDate) { $months = array(1 => "Jan", 2 => "Feb", 3 => "Mar", 4 => "Apr", 5 => "May", 6 => "Jun", 7 => "Jul", 8 => "Aug", 9 => "Sep", 10 => "Oct", 11 => "Nov", 12 => "Dec"); //We need something to reference the months. $pubDate = str_replace(" ", "", $pubDate); //Get rid of spaces $pubDate = str_replace(",", "", $pubDate); //Get rid of commas $pubDate = str_replace(":", "", $pubDate); //Finally, get rid of colons $pubDay = substr($pubDate, 3, 2); //Should get 13 $pubMonth = substr($pubDate, 5, 3); //Should get Mar, we'll format it later $pubYear = substr($pubDate, 8, 4); //Returns 2009 $pubHour = substr($pubDate, 12, 2); //Returns 11 $pubMin = substr($pubDate, 14, 2); //Returns 40 $pubSec = substr($pubDate, 16, 2); //Returns 02 $numMonth = array_search($pubMonth, $months); //Find the key or numerical value for the month. return mktime($pubHour, $pubMin, $pubSec, $numMonth, $pubDay, $pubYear); //return mktime($pubHour, $pubMin, $pubSec, $numMonth, $pubDay, $pubYear); } $time = "Fri, 13 Mar 2009 11:40:02 +0000"; //pubDate echo date("M-d-Y", pub2stamp($time)); //Make real date. ?> I tested it, it should work. It did on my server atleast. Link to comment https://forums.phpfreaks.com/topic/149228-rss-pubdate-to-time/#findComment-784483 Share on other sites More sharing options...
Jesper Posted March 18, 2009 Author Share Posted March 18, 2009 Yeah, I thought of that way too, but it isn't really efficient . Thanks tho, as it did help me find out where the problems was: the +0000 (etc.). I just used substr($var,0,-5), and it works fine as I'm using feeds with the Dutch time as pubDate anyways. Link to comment https://forums.phpfreaks.com/topic/149228-rss-pubdate-to-time/#findComment-788031 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.