PHP substr 和 strlen 的替代方案

发布于 2024-08-24 00:19:32 字数 114 浏览 3 评论 0原文

我听说 PHP 中有一些函数 substr() 和 strlen() 的替代方法可以处理更安全的位。这是真的吗?如果是的话,那么这些功能是什么?我听说它是​​基于函数 strcmp() 但我没有直接看到如何使用它。

I heard that in PHP there are some alternatives for the functions substr() and strlen() which handles safer bits. Is this true and if it is then what are those functions? I heard that it is based on the function strcmp() but I don't see directly how can I use it.

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

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

发布评论

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

评论(2

无需解释 2024-08-31 00:19:32

这些函数以 mb_ 为前缀。请参阅此处: http://php.net/manual/en/ref.mbstring.php

来自 PHP 的多字节字符串扩展的介绍:

mbstring 提供多字节特定字符串函数,帮助您处理 PHP 中的多字节编码。除此之外,mbstring 还处理可能的编码对之间的字符编码转换。 mbstring 旨在处理基于 Unicode 的编码,例如 UTF-8 和 UCS-2 以及许多单字节编码,以方便使用。

The functions are prefixed with mb_. See here: http://php.net/manual/en/ref.mbstring.php

From PHP's Multibyte String extension's introduction:

mbstring provides multibyte specific string functions that help you deal with multibyte encodings in PHP. In addition to that, mbstring handles character encoding conversion between the possible encoding pairs. mbstring is designed to handle Unicode-based encodings such as UTF-8 and UCS-2 and many single-byte encodings for convenience.

-小熊_ 2024-08-31 00:19:32

也许您的意思是对于多字节字符编码(如 UTF-8)是安全的。因为 substrstrlen 对于多字节编码不安全。他们将每个字符视为一个字节。但多字节字符串函数考虑到了这一点。

Maybe you mean safe for multibyte character encoding like UTF-8. Because substr and strlen are not safe for multibyte encodings. They count each character as one byte. But the multibyte string function take that into account.

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