开发者

SimplePie Encoding

I am using SimplePie to parse and display an xml feed on my site. I have two separate rss feeds and I running each one through SimplePie then displaying them in the side bar.

The problem I am having is that each feed contains smart quotes and they are displayed as odd characters in the browser. SimplePie has the encoding set as UTF-8, but the characters still show up.

I put in a small function to remove the quotes (below) but they still show up.

function killsmartquotes($content)
{
  $content = str_replace("”", "”", $content);
  $content = str_replace("“", "“", $content);
  $content = str_replace("‘", "‘", $content);
  $content = str_replace("’", "’", $content);
  $content = str_replace("—", "—", $c开发者_如何转开发ontent);

  return $content;
}


<?php foreach ($feeds[0]->get_items(0, 1) as $item): ?>
    <h5><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h5> 
    <p class="feed_description"><?php echo killsmartquotes($item->get_description()); ?></p>
    <br />
    <span><?php echo $item->get_date('j F Y'); ?> | <a href="#"><?php echo $site_names[0]; ?></a>
    </span>
<?php endforeach; ?>
</li>


Instead use htmlentities and do it like this:

 <?php echo htmlentities ($item->get_description(), ENT_COMPAT, "UTF-8"); ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜