wpcf7_count_code_units()CF7 1.0

Returns the number of code units in a string.

Хуков нет.

Возвращает

int|true|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 5.9.3

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;
	$text = str_replace( "\r\n", "\n", $text );

	$encoding = mb_detect_encoding( $text, mb_detect_order(), true );

	if ( $encoding ) {
		$text = mb_convert_encoding( $text, 'UTF-16', $encoding );
	} else {
		$text = mb_convert_encoding( $text, 'UTF-16', 'UTF-8' );
	}

	$byte_count = mb_strlen( $text, '8bit' );

	return floor( $byte_count / 2 );
}