如何防止显示菱形问号符号,即使使用 mb_substr 和 utf-8

发布于 2024-11-19 18:58:59 字数 495 浏览 7 评论 0原文

我读过其他一些问题,尝试了答案,但最终没有结果。我得到的是例如这个

Μήπως θα έπρεπε να � ...

,我无法删除那个奇怪的问号。我所做的就是获取 RSS feed 的内容,该内容也被编码为 使用希腊语作为内容。

有什么办法可以解决这个问题吗?

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<div><?php
    $entry->description = strip_tags($entry->description);
    echo mb_substr($entry->description, 0, 490);
?> ...</div>

I have read some other questions, tried the answers but got no result at the end. What I get is for example this

Μήπως θα έπρεπε να � ...

and I can't remove that weird question mark. What I do is to get the content of an RSS feed that is encoded also to
<?xml version="1.0" encoding="UTF-8"?> using Greek language for the content.

Is there any way to fix this?

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<div><?php
    $entry->description = strip_tags($entry->description);
    echo mb_substr($entry->description, 0, 490);
?> ...</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

深爱不及久伴 2024-11-26 18:59:00

这就是答案

mb_substr($entry->description, 0, 490, "UTF-8");

This is the answer

mb_substr($entry->description, 0, 490, "UTF-8");
帥小哥 2024-11-26 18:59:00

我相信问题出在你的编码上。您输出 UTF-8 但您的浏览器无法解释其中一个字符。我过去所知道的问号符号实际上是由浏览器生成的,因此没有搜索和替换......这是关于修复你的编码或在输出之前从字符串中消除未知字符......

如果你有权访问数据源,那么您可能需要检查数据库设置以确保其编码正确...如果没有,那么您将不得不找到某种方法来使用 php 转换数据...这不是一个简单的方法任务...

也许:

mb_convert_encoding($string, "UTF-8");

I believe the issue is with your encoding. Your outputting UTF-8 but your browser cannot interpret one of the characters. The question mark symbol as I have known it in the past is actually generated by the browser, so there is no search and replace....it's about fixing your encoding OR eliminating unknown characters from the string before outputting it...

If you have access to the source of data, then you may want to check the DB settings to make sure it's encoded properly...if not, then you'll have to find someway to convert the data over using php...not an easy task...

Perhaps:

mb_convert_encoding($string, "UTF-8");
薄暮涼年 2024-11-26 18:59:00

您是否尝试过使用这些看似多余的多字节安全字符串函数,这些函数不在 php 核心中?

http://code.google.com/p/mbfunctions/

他们似乎提供了 mb_strip_tags () 函数如下:

if (! function_exists('mb_strip_tags'))
{
   function mb_strip_tags($document,$repl = ''){
      $search = array('@<script[^>]*?>.*?</script>@si',  // Strip out javascript
                     '@<[\/\!]*?[^<>]*?>@si',            // Strip out HTML tags
                     '@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly
                     '@<![\s\S]*?--[ \t\n\r]*>@'         // Strip multi-line comments including CDATA
      );
      $text = mb_preg_replace($search, $repl, $document);
      return $text;
   }
}

Have you tried using these seemingly redundant multibyte safe string functions which are not in the php core?

http://code.google.com/p/mbfunctions/

It appears they offer an mb_strip_tags() function like such:

if (! function_exists('mb_strip_tags'))
{
   function mb_strip_tags($document,$repl = ''){
      $search = array('@<script[^>]*?>.*?</script>@si',  // Strip out javascript
                     '@<[\/\!]*?[^<>]*?>@si',            // Strip out HTML tags
                     '@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly
                     '@<![\s\S]*?--[ \t\n\r]*>@'         // Strip multi-line comments including CDATA
      );
      $text = mb_preg_replace($search, $repl, $document);
      return $text;
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文