= 0 && $ord0 <= 127 ) { $ord = $ord0; $increment = 1; } else { # 2 bytes $ord1 = ord($str{$i+1}); if ( $ord0 >= 192 && $ord0 <= 223 ) { $ord = ( $ord0 - 192 ) * 64 + ( $ord1 - 128 ); $increment = 2; } else { # 3 bytes $ord2 = ord($str{$i+2}); if ( $ord0 >= 224 && $ord0 <= 239 ) { $ord = ($ord0-224)*4096 + ($ord1-128)*64 + ($ord2-128); $increment = 3; } else { # 4 bytes $ord3 = ord($str{$i+3}); if ($ord0>=240 && $ord0<=247) { $ord = ($ord0-240)*262144 + ($ord1-128)*4096 + ($ord2-128)*64 + ($ord3-128); $increment = 4; } else { ob_end_clean(); trigger_error("utf8_to_ascii: looks like badly formed UTF-8 at byte $i"); return FALSE; } } } } $bank = $ord >> 8; # If we haven't used anything from this bank before, need to load it... if ( !array_key_exists($bank, $UTF8_TO_ASCII) ) { $bankfile = UTF8_TO_ASCII_DB. '/'. sprintf("x%02x",$bank).'.php'; if ( file_exists($bankfile) ) { # Load the appropriate database if ( !include $bankfile ) { ob_end_clean(); trigger_error("utf8_to_ascii: unable to load $bankfile"); } } else { # Some banks are deliberately empty $UTF8_TO_ASCII[$bank] = array(); } } $newchar = $ord & 255; if ( array_key_exists($newchar, $UTF8_TO_ASCII[$bank]) ) { echo $UTF8_TO_ASCII[$bank][$newchar]; } else { echo $unknown; } $i += $increment; } $str = ob_get_contents(); ob_end_clean(); return $str; }