【问题标题】:SimplePie RSS Parser - Encoding and Weird Characters even on UTF-8SimplePie RSS Parser - 即使在 UTF-8 上也能编码和奇怪的字符
【发布时间】:2012-03-07 14:46:14
【问题描述】:

我正在使用 SimplePie 解析 RSS 提要,我得到以下输出:

Don't forget our "Spot It, Post It" .....

我的代码是:

<?php
header('Content-type:text/html; charset=utf-8');
require_once('rss/simplepie.inc');

// We'll process this feed with all of the default options.
$feed = new SimplePie();

// Set which feed to process.
$feed->set_feed_url('FeedURL');
$feed->enable_cache(true);  
$feed->set_cache_duration(3600);  
$feed->set_cache_location('cache');
$feed->init();  
$feed->handle_content_type();  
?>

我正在使用 HTML5 Doctype 而且我也有:&lt;meta charset="charset=utf-8"&gt;

我已经查过了,所有内容都在谈论将字符集更改为 UTF-8,我显然拥有..所以我不太确定是什么原因造成的。

有什么想法吗?

【问题讨论】:

    标签: parsing encoding utf-8 rss simplepie


    【解决方案1】:

    我不知道您是否已设法解决此问题,但我想我会与其他正在寻找的人分享我的解决方案。我遇到了同样的问题——提要中的角色被“损坏”了。我的代码最初(有问题)是:

    <?php 
    include_once $_SERVER['DOCUMENT_ROOT'] . '/inc/simplepie.inc'; 
    $feed = new SimplePie('http://domain.wordpress.com/feed/');
    ?>
    

    看到上面的帖子,我尝试添加以下标题并且成功了!

    <?php 
    header('Content-type:text/html; charset=utf-8');
    include_once $_SERVER['DOCUMENT_ROOT'] . '/inc/simplepie.inc'; 
    $feed = new SimplePie('http://domain.wordpress.com/feed/');
    ?>
    

    我希望这可以帮助遇到同样问题的其他人。

    【讨论】:

      【解决方案2】:

      每个提要都会发生这种情况吗?或者只是一个特定的提要?它可能是饲料本身。如果描述本身有问题,您可以使用 $item->get_content() 并直接查看提要的内容。有时需要对来自提要或 Web API 的信息进行处理,有用于剥离和替换字符的 PHP 代码和示例,SimplePie 网站上的 News Blocks 2.0 演示有一些我最近一直在使用的清理代码。

      祝你好运。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-27
        • 1970-01-01
        • 2021-08-28
        相关资源
        最近更新 更多