我正在尝试通过PHP检索机箱的URL,但是收到的错误表明机箱是非对象的。当我在本地运行它时,此代码有效,但在上传到我的服务器并直接在站点上运行时似乎不起作用。它被插入到表达引擎页面fwiw。
$rss = new DOMDocument();
$rss->load('http://www.blueskyresumes.com/blog/feed/');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array(
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
'creator' => $node->getElementsByTagName('creator')->item(0)->nodeValue,
'image' => $node->getElementsByTagName('enclosure')->item(0) ? $node->getElementsByTagName('enclosure')->item(0)->getAttribute('url') : '',
);
array_push($feed, $item);
}
$limit = 3;
for ($x = 0; $x < $limit; $x++) {
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
$date = date('l F d, Y', strtotime($feed[$x]['date']));
$author = $feed[$x]['creator'];
$image = $feed[$x]['image'];
echo '<span><img src="'. $image . '" /></span><h4 class="blog_title"><a href="'.$link.'" title="'.$title.'">'.$title.'</a><br />';
echo '<small><em>by '.$author.'</em></small></h4>';
}