wpdb::check_ascii()protectedWP 4.2.0

Checks if a string is ASCII.

The negative regex is faster for non-ASCII strings, as it allows the search to finish as soon as it encounters a non-ASCII character.

Метод класса: wpdb{}

Хуков нет.

Возвращает

true|false. True if ASCII, false if not.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->check_ascii( $input_string );
$input_string(строка) (обязательный)
String to check.

Список изменений

С версии 4.2.0 Введена.

Код wpdb::check_ascii() WP 6.5.2

protected function check_ascii( $input_string ) {
	if ( function_exists( 'mb_check_encoding' ) ) {
		if ( mb_check_encoding( $input_string, 'ASCII' ) ) {
			return true;
		}
	} elseif ( ! preg_match( '/[^\x00-\x7F]/', $input_string ) ) {
		return true;
	}

	return false;
}