php - 获取内容:encoded from RSS feed

标签 php parsing rss feed

我用它来解析 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(' & ', ' &amp; ', $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/

相关文章:

测试 RSS 提要

iphone - 使用 GDataXMLDocument 解析 xml 属性

javascript - 无法转换 javascript 参数

php - 在 PHP 中使用 ' instead of "真的有影响吗

php - 如何处理 Material Design Light mdl-menu 中的事件

javascript - 如何将本地文件定义为 DOM 对象?

mysql - 在数据库中插入列表元素时创建 MySQL 唯一 ID

基于 Java 的 Atom/RSS 库,可在 Google App Engine 中运行

php - JSON + Jquery Ajax + PHP + MYSQL 出错

php - 在 Web 服务器中存储文件的安全方法?