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.
$input_stringstringrequired
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;
}
| Version | Description |
|---|---|
| 4.2.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wpdb/check_ascii