I took over a project with this "feature" enabled... took me a while to figure out why strings behaved non language standard. So, if you like to make grown men cry - by all means enable this deathtrap.
This feature has been DEPRECATED as of PHP 7.2.0. Relying on this feature is highly discouraged.
你也许常常会发现现存的 PHP 应用很难运行在多字节环境下。 发生这种情况的原因是大多数那种 PHP 应用使用了标准的字符串函数,类似 substr(),已知无法处理多字节编码的字符串。
mbstring 支持一个"函数重载"功能,将对应的多字节版本重载到标准字符处理函数上,例如你能够让这类应用在不修改代码的前提下添加多字节的处理能力。 比如,启用函数重载后,mb_substr() 将会代替 substr() 被调用。 在很多情况下这个功能允许让仅支持单字节编码的应用简单地和多字节环境对接。
要使用函数重载功能,设置 php.ini 里的 mbstring.func_overload 为正值,就是表示为重载函数分类的位掩码组合。 要重载 mail() 函数需要设置它为 1。字符串函数设置为 2,正则表达式函数为 4。 例如,当它设置为 7, mail、strings 和 正则表达式函数将都会被重载。 以下列表显示了重载的函数。
mbstring.func_overload 的值 | 原始函数 | 重载后的函数 |
---|---|---|
1 | mail() | mb_send_mail() |
2 | strlen() | mb_strlen() |
2 | strpos() | mb_strpos() |
2 | strrpos() | mb_strrpos() |
2 | substr() | mb_substr() |
2 | strtolower() | mb_strtolower() |
2 | strtoupper() | mb_strtoupper() |
2 | stripos() | mb_stripos() |
2 | strripos() | mb_strripos() |
2 | strstr() | mb_strstr() |
2 | stristr() | mb_stristr() |
2 | strrchr() | mb_strrchr() |
2 | substr_count() | mb_substr_count() |
4 | ereg() | mb_ereg() |
4 | eregi() | mb_eregi() |
4 | ereg_replace() | mb_ereg_replace() |
4 | eregi_replace() | mb_eregi_replace() |
4 | split() | mb_split() |
Note:
不推荐每个目录的范围(context)内使用函数重载选项,因为还无法确定在生产环境中是否稳定,也许会导致不确定的行为。
I took over a project with this "feature" enabled... took me a while to figure out why strings behaved non language standard. So, if you like to make grown men cry - by all means enable this deathtrap.
it's kinda evil and gives you tons of headache.
In short, only use mbstring.func_overload if you are 100% certain that nothing on your site relies on manipulating binary data in PHP.
In case you need to (de)activate the overloading for a specific directory, try setting an appropriate php_admin_value in your httpd.conf, e.g.
<Directory ...>
...
php_admin_value mbstring.func_overload 7
</Directory>
I'm not 100% sure if one can rely on that, but it seems to work for me.
It seems in php 5.2.7 - 5.2.9 under windows mbstring overloading not working in .htaccess files. Apache v.2.2.
Works only in php.ini, this is not convinient in some situations.