函数重载功能

Warning

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)内使用函数重载选项,因为还无法确定在生产环境中是否稳定,也许会导致不确定的行为。

相关文章
php 多字节字符串 函数 检查字符串在指定的编码里是否有效php 多字节字符串 函数 get a specific characterphp 多字节字符串 函数 对字符串进行大小写转换php 多字节字符串 函数 转换字符的编码php 多字节字符串 函数 convert kana one from another zen kaku han kaku and more php 多字节字符串 函数 returns start point for next regular expression matchphp 多字节字符串 函数 retrieve the result from the last multibyte regular expression matchphp 多字节字符串 函数 setup string and regular expression for a multibyte regular expression matchphp 多字节字符串 函数 returns position and length of a matched part of the multibyte regular expression for a predefined multibyte stringphp 多字节字符串 函数 returns the matched part of a multibyte regular expressionphp 多字节字符串 函数 get code point of characterphp 多字节字符串 函数 在输出缓冲中转换字符编码的回调函数php 多字节字符串 函数 解析 get/post/cookie 数据并设置全局变量php 多字节字符串 函数 获取 mime 字符串php 多字节字符串 函数 大小写不敏感地查找指定字符在另一个字符串中最后一次的出现php 多字节字符串 函数 大小写不敏感地在字符串中查找一个字符串最后出现的位置php 多字节字符串 函数 查找字符串在一个字符串中最后出现的位置php 多字节字符串 函数 查找字符串在另一个字符串里的首次出现php 字符串 函数 转换字符串第一个字节为 0 255 之间的值php 多字节字符串 函数重载功能
关注编程学问公众号