*/
static function isUtf8( $value, $disableMbstring = false ) {
$value = (string)$value;
- if ( preg_match( "/[\x80-\xff]/S", $value ) === 0 ) {
- // String contains only ASCII characters, has to be valid
- return true;
- }
// If the mbstring extension is loaded, use it. However, before PHP 5.4, values above
// U+10FFFF are incorrectly allowed, so we have to check for them separately.
( $newPHP || preg_match( "/\xf4[\x90-\xbf]|[\xf5-\xff]/S", $value ) === 0 );
}
+ if ( preg_match( "/[\x80-\xff]/S", $value ) === 0 ) {
+ // String contains only ASCII characters, has to be valid
+ return true;
+ }
+
// PCRE implements repetition using recursion; to avoid a stack overflow (and segfault)
// for large input, we check for invalid sequences (<= 5 bytes) rather than valid
// sequences, which can be as long as the input string is. Multiple short regexes are