wpdb::check_ascii() WordPress Method

The wpdb::check_ascii() method is used to check if a given string is ASCII. ASCII is a character encoding standard that is used to represent text in computers. This method is useful for checking if a given string is composed entirely of ASCII characters.

wpdb::check_ascii( string $string ) #

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.


Top ↑

Parameters

$string

(string)(Required)String to check.


Top ↑

Return

(bool) True if ASCII, false if not.


Top ↑

Source

File: wp-includes/wp-db.php

	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;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.