Rss Feed显示1970-01-01 pubDate?

My rss feed show 1970-01-01 pubDate on my mobilesite and shows correct pubDate on the website. Is the feed corupt ? It was working 3 days ago thou.

Or maybe ive written the format in a non standard way ?

    function get_rss($url, $lang) {
    $rss = new rss_php;
    $rss->load($url);
    $items = $rss->getItems();

    // Sets the maximum items to be listed
    $max_items = 5;

    $count = 0;

    $html = '';
    foreach($items as $index => $item) {
    $pubdate = date("Y-m-d", strtotime(substr($item['pubDate'], 4)));
    $html .= '
    <ul class="rssList">
    <li class="itemDate"><span>' . $pubdate . '</span></li>
    <li class="itemTitle"><a href="'.$item['link'].'"                 title="'.$item['title'].'"                         rel="external">        
 <h2>'.$item['title'].'</h2></a></li>
    <li class="itemText"><span>'.$item['description'].'<span></li>
    </ul>';
    $count++; //Increase the value of the count by 1
    if($count==$max_items) break; //Break the loop is count is equal to the max_loop
    }    
     echo $html;
    }

Definition of rss_php

        class rss_php {

    public $document;
    public $channel;
    public $items;

    # load RSS by URL
        public function load($url=false, $unblock=true) {
            if($url) {
                if($unblock) {
                    $this->loadParser(file_get_contents($url, false, $this->randomContext()));
                } else {
                    $this->loadParser(file_get_contents($url));
                }
            }
        }
    # load raw RSS data
        public function loadRSS($rawxml=false) {
            if($rawxml) {
                $this->loadParser($rawxml);
            }
        }

Parser

   private function loadParser($rss=false) {
    if($rss) {
        $this->document = array();
        $this->channel = array();
        $this->items = array();
        $DOMDocument = new DOMDocument;
        $DOMDocument->strictErrorChecking = false;
        $DOMDocument->loadXML($rss);
        $this->document = $this->extractDOM($DOMDocument->childNodes);
    }
}

The problem is probably with the locale settings. It's unable to translate the month "okt" (should be "oct" in English), but was working fine with "sep" (same in English). The strtotime() function only works in English but explains why it was working a few days ago, but not now.

You have three options:

  1. You can fix the way dates are generated with strtotime using setlocale(). You need this in your RSS class, set the locale to English and output the dates.

  2. Use CreateFromFormat() when reading the string, in conjunction with SetLocale when reading the date. You should be able to translate a foreign date.

  3. Manually parse the date yourself. Preg_match() could be a good starter for that.

Option 1 is probably easiest, if you can.


Edit (based on comments and edited question)

As the item data is coming straight from the rss feed (and is not self-generated) then you're probably up for option 3 (manually parse the string yourself). As you're ignoring the days of the week, the only bit you need to convert is the month, so use str_replace:

foreach($items as $index => $item) {
    $pubdateForeignString = substr($item['pubDate'], 4);
    $pubdateEnglishString = str_replace(array('mai', 'okt', 'dez'), array('may', 'oct', 'dec'), $pubdateForeignString);
    $pubdate = date("Y-m-d", strtotime($pubdateEnglishString));

You only need to convert the months that are different - I've taken a stab at German, but if in doubt you could use date('M') in a loop with setlocale().

For some reason and for an item in your for loop the $item['pubDate'] is not defined (or it contains garbage) and date defaults to 1970-01-01. Make sure that your variable is always set and contains a date in a valid format.

Debug your loop and for each item print its contents: var_dump($item['pubDate']) to investigate further