_wp_is_valid_utf8_fallback( string $bytes ): bool

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Fallback mechanism for safely validating UTF-8 bytes.

Description

See also

Parameters

$bytesstringrequired
String which might contain text encoded as UTF-8.

Return

bool Whether the provided bytes can decode as valid UTF-8.

Source

function _wp_is_valid_utf8_fallback( string $bytes ): bool {
	$bytes_length = strlen( $bytes );
	if ( 0 === $bytes_length ) {
		return true;
	}

	$next_byte_at   = 0;
	$invalid_length = 0;

	_wp_scan_utf8( $bytes, $next_byte_at, $invalid_length );

	return $bytes_length === $next_byte_at && 0 === $invalid_length;
}

Changelog

VersionDescription
6.9.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.