wpdb::check_ascii( string $string )

Checks if a string is ASCII.


Description 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 Parameters

$string

(string) (Required) String to check.


Top ↑

Return Return

(bool) True if ASCII, false if not.


Top ↑

Source 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

Changelog
Version Description
4.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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