我正在使用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>发布于 2010-08-28 23:20:14
取而代之的是使用htmlentities,如下所示:
<?php echo htmlentities ($item->get_description(), ENT_COMPAT, "UTF-8"); ?>https://stackoverflow.com/questions/3591221
复制相似问题