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>

图片转代码服务由CSDN问答提供 功能建议

我使用SimplePie在我的网站上解析和显示xml提要。 我有两个单独的RSS源,我通过SimplePie运行每个源,然后在侧栏中显示它们。

我遇到的问题是每个Feed都包含智能引号,并且它们在浏览器中显示为奇数字符。 SimplePie的编码设置为UTF-8,但字符仍然显示。

我输入一个小函数来删除引号(如下所示),但它们仍会显示。

  function killsmartquotes($ content)
 {
 $ content = str_replace(“”“,”&amp; rdquo;“,$ content); 
 $ content = str_replace(”  “”,“&amp; ldquo;”,$ content); 
 $ content = str_replace(“'”,“&amp; lsquo;”,$ content); 
 $ content = str_replace(“'”,“&amp;  rsquo;“,$ content); 
 $ content = str_replace(” - “,”&amp; mdash;“,$ content); 
 
返回$ content; 
} 
 
 
&lt;?php  foreach($ feeds [0]  - &gt; get_items(0,1)为$ item):?&gt; 
&lt; h5&gt;&lt; a href =“&lt;?php echo $ item-&gt; get_permalink();  ?&gt;“&gt;&lt;?php echo $ item-&gt; get_title();  ?&GT;&LT; / A&GT;&LT; / H5&GT;  
&lt; p class =“feed_description”&gt;&lt;?php echo killsmartquotes($ item-&gt; get_description());  ?&gt;&lt; / p&gt; 
&lt; br /&gt; 
&lt; span&gt;&lt;?php echo $ item-&gt; get_date('j F Y');  ?&GT;  |  &lt; a href =“#”&gt;&lt;?php echo $ site_names [0];  ?&gt;&lt; / a&gt; 
&lt; / span&gt; 
&lt;?php endforeach;  ?&gt; 
&lt; / li&gt; 
   
 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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"); ?>
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题