简单饼图编码

发布于 2024-09-16 01:50:38 字数 1099 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半夏半凉 2024-09-23 01:50:38

而是使用 htmlentities 并执行以下操作:

 <?php echo htmlentities ($item->get_description(), ENT_COMPAT, "UTF-8"); ?>

Instead use htmlentities and do it like this:

 <?php echo htmlentities ($item->get_description(), ENT_COMPAT, "UTF-8"); ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文