do not recalculate strlen in each loop in utf8 lib
Ignore-this: 2e2f6983f0c1b891825b0c1954b7727d darcs-hash:20091020201938-7ad00-7b5501c2acc9f5ac280e73d25e1cccbcb3237356.gz
This commit is contained in:
parent
4fa35cd990
commit
8ec3f7bdbf
18
inc/utf8.php
18
inc/utf8.php
|
@ -78,13 +78,14 @@ if(!function_exists('utf8_strip')){
|
|||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
function utf8_strip($str){
|
||||
$ascii = '';
|
||||
for($i=0; $i<strlen($str); $i++){
|
||||
if(ord($str{$i}) <128){
|
||||
$ascii .= $str{$i};
|
||||
$ascii = '';
|
||||
$len = strlen($str);
|
||||
for($i=0; $i<$len; $i++){
|
||||
if(ord($str{$i}) <128){
|
||||
$ascii .= $str{$i};
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ascii;
|
||||
return $ascii;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,7 +97,8 @@ if(!function_exists('utf8_check')){
|
|||
* @link http://www.php.net/manual/en/function.utf8-encode.php
|
||||
*/
|
||||
function utf8_check($Str) {
|
||||
for ($i=0; $i<strlen($Str); $i++) {
|
||||
$len = strlen($Str);
|
||||
for ($i=0; $i<$len; $i++) {
|
||||
$b = ord($Str[$i]);
|
||||
if ($b < 0x80) continue; # 0bbbbbbb
|
||||
elseif (($b & 0xE0) == 0xC0) $n=1; # 110bbbbb
|
||||
|
@ -107,7 +109,7 @@ if(!function_exists('utf8_check')){
|
|||
else return false; # Does not match any model
|
||||
|
||||
for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
|
||||
if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))
|
||||
if ((++$i == $len) || ((ord($Str[$i]) & 0xC0) != 0x80))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue