wpcf7_count_code_units()CF7 1.0

Returns the number of code units in a string.

Хуков нет.

Возвращает

int|false. The number of code units, or false if mb_convert_encoding is not available.

Использование

wpcf7_count_code_units( $text );
$text(строка) (обязательный)
Input string.

Код wpcf7_count_code_units() CF7 6.1.6

function wpcf7_count_code_units( $text ) {
	static $use_mb = null;

	if ( is_null( $use_mb ) ) {
		$use_mb = function_exists( 'mb_convert_encoding' );
	}

	if ( ! $use_mb ) {
		return false;
	}

	$text = (string) $text;

	if ( '' === $text ) {
		return 0;
	}

	$text = str_replace( "\r\n", "\n", $text );

	$text = mb_convert_encoding(
		$text,
		'UTF-16',
		mb_detect_encoding( $text, mb_detect_order(), true ) ?: 'UTF-8'
	);

	return intdiv( mb_strlen( $text, '8bit' ), 2 );
}