douzhang5295 2010-08-28 15:06
浏览 18
已采纳

SimplePie编码

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("—", "—", $content);

  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>
  • 写回答

1条回答 默认 最新

  • duadpnld426905 2010-08-28 15:20
    关注

    Instead use htmlentities and do it like this:

     <?php echo htmlentities ($item->get_description(), ENT_COMPAT, "UTF-8"); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)