_mb_strlen()WP 4.2.0

Internal compat function to mimic mb_strlen().

Only supports UTF-8 and non-shifting single-byte encodings. For all other encodings expect the counts to be wrong. When the given encoding (or the blog_charset if none is provided) isn’t UTF-8 then the function returns the byte-count of the provided string.

Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.

No Hooks.

Returns

Int. Count of code points if UTF-8, byte length otherwise.

Usage

_mb_strlen( $str, $encoding );
$str(string) (required)
The string to retrieve the character length from.
$encoding(string|null)
Count characters according to this encoding.
Default: to consult blog_charset

Changelog

Since 4.2.0 Introduced.

_mb_strlen() code WP 7.0

function _mb_strlen( $str, $encoding = null ) {
	return _is_utf8_charset( $encoding ?? get_option( 'blog_charset' ) )
		? _wp_utf8_codepoint_count( $str )
		: strlen( $str );
}