简单饼图编码
我正在使用 SimplePie 解析并在我的网站上显示 xml feed。我有两个独立的 rss 提要,我通过 SimplePie 运行每个提要,然后将它们显示在侧栏中。
我遇到的问题是每个提要都包含智能引号,并且它们在浏览器中显示为奇怪的字符。 SimplePie 将编码设置为 UTF-8,但字符仍然显示。
我添加了一个小函数来删除引号(如下),但它们仍然显示。
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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而是使用
htmlentities
并执行以下操作:Instead use
htmlentities
and do it like this: