2012-03-07 27 views
0

我使用了SimplePie解析一個RSS feed,而我得到以下的輸出:了SimplePie RSS解析器 - 編碼和怪誕形象甚至UTF-8

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文檔類型,我也有:<meta charset="charset=utf-8">

我看着它,有關更改字符集爲UTF-8,我已清楚一切談判..所以我也不太知道還有什麼是造成這一點。

任何想法?

回答

1

這是發生在每個飼料?或者只是一個特定的飼料?它可能是飼料本身。您可以使用$ item-> get_content()並直接查看Feed的內容,如果描述本身證明有問題。有時需要對Feed或Web API的信息進行處理,PHP代碼和剝離和替換字符的示例,SimplePie網站上的News Blocks 2.0演示有一些我最近使用過的清理代碼。

祝你好運。

2

我不知道你是否已經設法解決這個問題,但是我以爲我會和其他正在尋找的人分享我的解決方案。我有同樣的問題 - 字符在Feed中被「損壞」。我的代碼最初(與問題)是:

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

我希望這可以幫助其他人經歷相同的問題。