我的 rss 提要在我的移动网站上显示 1970-01-01 pubDate,并在网站上显示正确的 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);
}
}