我正在使用 SimplePie 在我的网站上解析和显示 xml 提要。我有两个单独的 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>