私のRSSフィードは私のモバイルサイトで1970-01-01pubDateを表示し、Webサイトで正しいpubDateを表示します。フィードが破損していませんか?それは3日前に働いていました。
それとも、非標準的な方法でフォーマットを書いたのでしょうか?
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;
}
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);
}
}
パーサー
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);
}
}