启用func_overload时,将mbstring内部编码设置为二进制安全编码。
原型
mbstring_binary_safe_encoding( bool $reset = false )
描述
当mbstring.func_overload用于多字节编码时,strlen()和类似函数的结果会影响utf8字符,导致二进制数据返回不正确的长度。
参考:
- reset_mbstring_encoding()
参数
$reset
(bool)
(Optional)
是否将编码重置为先前设置的编码。
源文件
路径:wp-includes/functions.php
<?php
...
function mbstring_binary_safe_encoding( $reset = false ) {
static $encodings = array();
static $overloaded = null;
if ( is_null( $overloaded ) )
$overloaded = function_exists( 'mb_internal_encoding' ) && ( ini_get( 'mbstring.func_overload' ) & 2 );
if ( false === $overloaded )
return;
if ( ! $reset ) {
$encoding = mb_internal_encoding();
array_push( $encodings, $encoding );
mb_internal_encoding( 'ISO-8859-1' );
}
if ( $reset && $encodings ) {
$encoding = array_pop( $encodings );
mb_internal_encoding( $encoding );
}
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/mbstring_binary_safe_encoding/