返回介绍

mbstring_binary_safe_encoding()

发布于 2017-09-11 01:48:42 字数 3147 浏览 1111 评论 0 收藏 0

mbstring_binary_safe_encoding( bool $reset = false )

Set 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.


参数

$reset

(bool) (Optional) Whether to reset the encoding back to a previously-set encoding.

Default value: false


源代码

File: wp-includes/functions.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 );
	}
}

更新日志

Versiondescription
3.7.0Introduced.

相关函数

Used By

  • wp-includes/wp-db.php: wpdb::strip_invalid_text()
  • wp-admin/includes/class-wp-filesystem-ftpext.php: WP_Filesystem_FTPext::put_contents()
  • wp-admin/includes/class-wp-filesystem-direct.php: WP_Filesystem_Direct::put_contents()
  • wp-admin/includes/image.php: wp_read_image_metadata()
  • wp-admin/includes/class-wp-filesystem-ftpsockets.php: WP_Filesystem_ftpsockets::dirlist()
  • wp-admin/includes/class-wp-filesystem-ftpsockets.php: WP_Filesystem_ftpsockets::get_contents()
  • wp-admin/includes/class-wp-filesystem-ftpsockets.php: WP_Filesystem_ftpsockets::put_contents()
  • wp-admin/includes/file.php: _unzip_file_pclzip()
  • wp-includes/formatting.php: seems_utf8()
  • wp-includes/formatting.php: utf8_uri_encode()
  • wp-includes/functions.php: reset_mbstring_encoding()
  • wp-includes/class-http.php: WP_Http::request()
  • Show 7 more used by Hide more used by

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文