On this page
mbstring_binary_safe_encoding( bool $reset = false )
Sets the mbstring internal encoding to a binary safe encoding when func_overload is enabled.
Description
When mbstring.func_overload is in use for multi-byte encodings, the results from strlen() and similar functions respect the utf8 characters, causing binary data to return incorrect lengths.
This function overrides the mbstring encoding to a binary-safe encoding, and resets it to the users expected encoding afterwards through the reset_mbstring_encoding function.
It is safe to recursively call this function, however each mbstring_binary_safe_encoding() call must be followed up with an equal number of reset_mbstring_encoding() calls.
See also
Parameters
$resetbool Optional-
Whether to reset the encoding back to a previously-set encoding.
Default:
false
Source
File: wp-includes/functions.php. View all references
function mbstring_binary_safe_encoding( $reset = false ) {
static $encodings = array();
static $overloaded = null;
if ( is_null( $overloaded ) ) {
if ( function_exists( 'mb_internal_encoding' )
&& ( (int) ini_get( 'mbstring.func_overload' ) & 2 ) // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated
) {
$overloaded = true;
} else {
$overloaded = false;
}
}
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 );
}
}
Related
Used By
| Used By | Description |
|---|---|
| verify_file_signature() wp-admin/includes/file.php | Verifies the contents of a file against its ED25519 signature. |
| wpdb::strip_invalid_text() wp-includes/class-wpdb.php | Strips any invalid characters based on value/charset pairs. |
| WP_Filesystem_FTPext::put_contents() wp-admin/includes/class-wp-filesystem-ftpext.php | Writes a string to a file. |
| WP_Filesystem_Direct::put_contents() wp-admin/includes/class-wp-filesystem-direct.php | Writes a string to a file. |
| wp_read_image_metadata() wp-admin/includes/image.php | Gets extended image metadata, exif or iptc as available. |
| WP_Filesystem_ftpsockets::dirlist() wp-admin/includes/class-wp-filesystem-ftpsockets.php | Gets details for files in a directory or a specific file. |
| WP_Filesystem_ftpsockets::get_contents() wp-admin/includes/class-wp-filesystem-ftpsockets.php | Reads entire file into a string. |
| WP_Filesystem_ftpsockets::put_contents() wp-admin/includes/class-wp-filesystem-ftpsockets.php | Writes a string to a file. |
| _unzip_file_pclzip() wp-admin/includes/file.php | Attempts to unzip an archive using the PclZip library. |
| seems_utf8() wp-includes/formatting.php | Checks to see if a string is utf8 encoded. |
| utf8_uri_encode() wp-includes/formatting.php | Encodes the Unicode values to be used in the URI. |
| WP_Http::request() wp-includes/class-wp-http.php | Send an HTTP request to a URI. |
| reset_mbstring_encoding() wp-includes/functions.php | Resets the mbstring internal encoding to a users previously set encoding. |
Changelog
| Version | Description |
|---|---|
| 3.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/mbstring_binary_safe_encoding