0

我正在使用 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 而且我还有:<meta charset="charset=utf-8">

我已经查过了,一切都在谈论将字符集更改为我显然拥有的 UTF-8 ......所以我不太确定还有什么原因导致这种情况。

有任何想法吗?

4

2 回答 2

2

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

<?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/');
?>

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

于 2012-05-21T21:53:04.607 回答
1

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

祝你好运。

于 2012-03-07T21:48:23.643 回答