diff options
author | Andreas Haerter <netzmeister@andreas-haerter.de> | 2009-07-24 10:40:09 +0200 |
---|---|---|
committer | Andreas Haerter <netzmeister@andreas-haerter.de> | 2009-07-24 10:40:09 +0200 |
commit | f2da7e0bcc3c9c38f4b14e42b4632291343bf343 (patch) | |
tree | 75bd79dc82262693124f36d0fc465abcd433732f | |
parent | 904b41ec0f8bd77ac8f1fed1c3ef5b6531476d27 (diff) | |
download | rpg-f2da7e0bcc3c9c38f4b14e42b4632291343bf343.tar.gz rpg-f2da7e0bcc3c9c38f4b14e42b4632291343bf343.tar.bz2 |
Much faster version of utf8_isASCII()
Ignore-this: 1adbc2b33e76b3a76e650c340e9644e6
This version uses a non-capturing regular expression instead of looping through
all characters of the string.
darcs-hash:20090724084009-2cb76-ad1630c7aca53f0bdb596525b0693304a9b4cc88.gz
-rw-r--r-- | inc/utf8.php | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/inc/utf8.php b/inc/utf8.php index e2f016942..85e5f4f7e 100644 --- a/inc/utf8.php +++ b/inc/utf8.php @@ -62,13 +62,10 @@ if(!function_exists('utf8_isASCII')){ /** * Checks if a string contains 7bit ASCII only * - * @author Andreas Gohr <andi@splitbrain.org> + * @author Andreas Haerter <netzmeister@andreas-haerter.de> */ function utf8_isASCII($str){ - for($i=0; $i<strlen($str); $i++){ - if(ord($str{$i}) >127) return false; - } - return true; + return (preg_match('/(?:[^\x00-\x7F])/', $str) !== 1); } } |