wordpress / latest / classes / wpdb / check_ascii.html

wpdb::check_ascii( string $string ): bool

Checks if a string is ASCII.

Description

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.

Parameters

$string string Required
String to check.

Return

bool True if ASCII, false if not.

Source

File: wp-includes/class-wpdb.php. View all references

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

	return false;
}

Used By

Used By Description

Changelog

Version Description
4.2.0 Introduced.

© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wpdb/check_ascii