且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP:特殊字符成为子字符串中的问号图标

更新时间:2023-02-19 13:02:17

听起来您正在使用 8 位字符串函数来处理 unicode 字符.那行不通.

Sounds like you are using 8bit string functions to process unicode characters. That cannot work.

您应该安装 mbstring 包并在您的 php 配置中启用mbstring 函数重载".这将注意以静默方式覆盖所有相关的字符串处理函数以使用它们的多字节安全等价物,这样您就不必更改代码.

You should install the mbstring package and enable "mbstring function overloading" in your php configuration. That will take care to silently override all relevant string handling functions to use their multi byte safe equivalents instead, so that you do not have to change your code.

该mbstring"扩展有许多配置选项.检查您的 php.ini 配置文件并查看它们.您将找到mbstring.func_overload 命令,您可能希望将其设置为值7,以便覆盖所有 此类函数.更改该配置后,您必须重新启动 http 服务器进程,以便加载新配置.您还可以通过在测试脚本中使用著名的 phpinfo() 函数来检查这一点.

There are a number of configuration options for that "mbstring" extension. Check your php.ini configuration file and look through them. You will find the mbstring.func_overload command which you probably want to set to the value 7, so that all such functions are overridden. After changing that configuration you have to restart your http server process, so that the new configuration gets loaded. You can also check that by using the famous phpinfo() function in a test script.

另一种方法是不配置此覆盖​​自动魔术,而是手动移植您的代码以直接使用这些功能.为此,您必须将代码中的 all 字符串函数调用替换为它们的等效函数名称.例如 mb_substr(...) 而不是 substr(...).

An alternative would be not to configure this overriding automagic, but to manually port your code to directly use those functions. For that you will have to replace all string function calls in your code by their equivalent function names. So for example mb_substr(...) instead of just substr(...).

此外,您真的想开始阅读您使用的工具的文档.这里对那些多字节字符串"函数的介绍很有趣.它应该可以帮助您了解这一切是关于什么以及您必须注意什么:http://php.net/manual/en/book.mbstring.php

Also you really want to start reading the documentation of the tools you use. Here the introduction to those "multi byte string" functions is of interest. It should help you to understand what this all is about and what you have to take care of: http://php.net/manual/en/book.mbstring.php