在 UTF-8 字符串中查找空格,是否需要 mb_strpos?

发布于 2024-12-22 00:34:54 字数 124 浏览 6 评论 0原文

我有一个 UTF-8 格式的字符串。

$string = "ãçé êíõ";

我需要找到空间的位置。 我必须使用 mb_strpos($string,' '); ?

I have a string in UTF-8.

$string = "ãçé êíõ";

I need to find the position of the space.
I have to use mb_strpos($string,' '); ?

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

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

发布评论

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

评论(2

一直在等你来 2024-12-29 00:34:54

如果您想找到空格的字符位置,那么可以。 strpos 不会这样做,因为字节值 0x20(空格的 UTF-8 代码点)也可能作为代码点 通过多个字节进行编码

另外,不要忘记指定编码 - 要么在 mb_strpos 调用中显式指定,要么通过使用 mb_internal_encoding

If you want to find the character position of the space, then yes. strpos will not do because the byte value 0x20 (UTF-8 code point for space) can also be encountered as part of a code point encoded over multiple bytes.

Also, do not forget to specify the encoding -- either explicitly on the mb_strpos call or by setting a default with mb_internal_encoding.

雄赳赳气昂昂 2024-12-29 00:34:54

请注意,仅使用 mb_strpos 可能还不够 - 有多个代码点显示为空格。请参见例如 此列表 - 第二个最常见的空格字符(第二个)默认 ASCII 空格 U+0020,十进制 32)是不可破坏的空格 (U+00A0);您可能还需要检查该字符 - 或者将其替换为“常用”空格字符。

Note that just using mb_strpos may not be sufficient - there are several code points that display as a space. See e.g. this list - the second most common space character (second to the default ASCII space U+0020, decimal 32) is the nonbreakable space (U+00A0); you may need to check for that one, too - or replace it into the "usual" space character.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文