我用它来解析 RSS feed 中的内容:
$rss = new DOMDocument();
$rss->load($feedurl);
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array(
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'content' => $node->getElementsByTagName('content:encoded')
->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
'guid' => $node->getElementsByTagName('guid')->item(0)->nodeValue,
);
array_push($feed, $item);
}
$limit = 1;
for ($x = 0; $x < $limit; $x++) {
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$content = $feed[$x]['content'];
$guid = $feed[$x]['guid'];
}
并将内容分配给变量。
除了那个之外,所有的都在工作。为什么是这样?
请有人帮我解决这个问题:)
最佳答案
遇到类似的问题,我点击了 fortytwo 提到的链接 并发现this answer它没有像显示的那样工作(将提交对该答案的编辑),尽管经过一些小的编辑,我能够让它按需要工作。这使得事情变得非常简单。
<?php
$xml=("https://en.blog.wordpress.com/feed/");
function getFeed($feed_url) {
$feeds = file_get_contents($feed_url);
$feeds = str_replace("<content:encoded>","<contentEncoded>",$feeds);
$feeds = str_replace("</content:encoded>","</contentEncoded>",$feeds);
$rss = simplexml_load_string($feeds);
echo "<ul>";
$x=$rss;
foreach($x->channel->item as $entry) {
echo "<li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>";
echo "<li>$entry->contentEncoded</li>";
}
echo "</ul>";
}
getFeed($xml);
关于php - 获取内容:encoded from RSS feed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13409692/