我正在尝试使用SimplePie解析客户端的RSS源(客户端是华盛顿邮报的作者)。SimplePie 1.3字符编码问题
阅读完文档并使用示例代码作为参考之后,我能够将提要解析到网站中,但现在我遇到了撇号字符未解码的问题('显示作为')
我试图在FAQ了SimplePie使用建议的解决方案来解决这个问题:1. 验证,该网站的meta标签 2.使用了SimplePie的handle_content_type()函数 3.使用PHP的内置标题()函数来纠正HTTP标头
不幸的是没有一个e已经为我解决了这个问题。
下面是我使用来解析RSS提要的代码:
<?php
require_once('php/autoloader.php');
$feedJB = new SimplePie();
$feedJB->set_feed_url('http://washingtontimes.dynamic.feedsportal.com/pf/637323/communities.washingtontimes.com/neighborhood/feeds/latest/status-update/');
$feedJB->init();
$feedJB->handle_content_type();
$feedRB = new SimplePie();
$feedRB->set_feed_url('http://washingtontimes.dynamic.feedsportal.com/pf/637323/communities.washingtontimes.com/neighborhood/feeds/latest/2nd-golden-era-advertising/');
$feedRB->init();
$feedRB->handle_content_type();
?>
这是页面上的输出代码:我已经在我的机器本地测试这个
<!-- Left -->
<li class="left">
<h3>Recent Posts</h3>
<ul class="feed-list">
<?php foreach ($feedJB->get_items(0, 5) as $item): ?>
<li>
<strong><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></strong>
<small>Posted on <?php echo $item->get_date('j F Y'); ?></small>
</li>
<?php endforeach; ?>
<li><h4><a href="<?php echo $feedJB->get_permalink(); ?>">Read more articles by Jeff</a></h4></li>
</ul>
</li>
<!-- /Left -->
<!-- Right -->
<li class="right">
<h3>Recent Posts</h3>
<ul class="feed-list">
<?php foreach ($feedRB->get_items(0, 5) as $item): ?>
<li>
<strong><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></strong>
<small>Posted on <?php echo $item->get_date('j F Y'); ?></small>
</li>
<?php endforeach; ?>
<li><h4><a href="<?php echo $feedRB->get_permalink(); ?>">Read more articles by Rob</a></h4></li>
</ul>
</li>
<!-- /Right -->
(运行MAMP的Mac Pro Lion)以及我的网络服务器(Linux运行Apache 2.2.22 & PHP 5.2.17)。
您还可以查看本作的时间去以下链接为: http://clients.josephmainwaring.com/statuscreative/#!columns.php
如果任何人有意见,以解决字符编码问题,将不胜感激。
尝试更换使用$文本与右单引号(或’)撇号(')= str_replace函数( “'”,“””,$文字); (代码仅用于清晰) – Waygood 2012-08-13 16:29:13
@ Waygood - 感谢您的建议,但它没有工作... – theaccordance 2012-08-13 19:38:17