Php SimplePie 1.3字符编码问题

Php SimplePie 1.3字符编码问题,php,character-encoding,rss,simplepie,Php,Character Encoding,Rss,Simplepie,我正试图使用SimplePie解析客户端的RSS提要(客户端是《华盛顿邮报》的作者) 在阅读文档并使用示例代码作为参考之后,我能够将提要解析到站点中,但是现在我遇到了一个问题,撇号字符没有被解码('显示为') 我已尝试使用SimplePie常见问题解答中建议的解决方案来解决此问题: 1.已验证站点的元标记 2.使用SimplePie的handle\u content\u type()函数 3.使用PHP的内置header()函数更正HTTP头 不幸的是,这些都没有解决我的问题 下面是我用来解析R

我正试图使用SimplePie解析客户端的RSS提要(客户端是《华盛顿邮报》的作者)

在阅读文档并使用示例代码作为参考之后,我能够将提要解析到站点中,但是现在我遇到了一个问题,撇号字符没有被解码('显示为')

我已尝试使用SimplePie常见问题解答中建议的解决方案来解决此问题: 1.已验证站点的元标记 2.使用SimplePie的handle\u content\u type()函数 3.使用PHP的内置header()函数更正HTTP头

不幸的是,这些都没有解决我的问题

下面是我用来解析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的macprolion)和我的web服务器(运行apache2.2.22和php5.2.17的Linux)上进行了本地测试

    您还可以通过转到以下链接暂时查看此内容:


    如果有人对解决字符编码问题有任何建议,我们将不胜感激

    我发现《华盛顿邮报》的提要都是ISO-8859-1格式的,即使它们包含UTF-8字符。我不使用SimplePie,但每次获取提要时,我都会通过以下函数运行它,
    $xml
    是提要的文本,
    $url
    是提要的url:

    function feed_fix_broken ( $xml, $url ) {
      $xml = iconv('UTF-8', 'UTF-8//IGNORE', $xml );
      $broken = array ('washingtonpost.com' => 'ISO-8859-1');
      foreach ($broken as $domain => $encoding) {
        if (stristr($url, $domain)) {
          $xml = iconv( 'UTF-8', $encoding.'//TRANSLIT', $xml );
        }
      }
      return $xml;
    }
    
    在可能的情况下,这会将UTF-8编码实体音译为ISO-8859-1对应实体

    请注意,在FeedDemon中,“查韦斯”有点疯狂

    但我做对了


    尝试使用$text=str_replace(“,”,$text)将撇号(';)替换为右单引号(’;或&rsquo;);(代码仅用于澄清)@Waygood-感谢您的建议,但它不起作用。。。