Subversion Repositories eFlore/Applications.cel

Rev

Rev 601 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 601 Rev 602
Line 880... Line 880...
880
    foreach($cp1252_map as $k=>$v){
880
    foreach($cp1252_map as $k=>$v){
881
        $byte_map[$k]=$v;
881
        $byte_map[$k]=$v;
882
    }
882
    }
883
}
883
}
Line 884... Line -...
884
 
-
 
885
$byte_map=array();
-
 
886
init_byte_map();
-
 
887
$ascii_char='[\x00-\x7F]';
-
 
888
$cont_byte='[\x80-\xBF]';
-
 
889
$utf8_2='[\xC0-\xDF]'.$cont_byte;
-
 
890
$utf8_3='[\xE0-\xEF]'.$cont_byte.'{2}';
-
 
891
$utf8_4='[\xF0-\xF7]'.$cont_byte.'{3}';
-
 
892
$utf8_5='[\xF8-\xFB]'.$cont_byte.'{4}';
-
 
893
$nibble_good_chars = "@^($ascii_char+|$utf8_2|$utf8_3|$utf8_4|$utf8_5)(.*)$@s";
-
 
894
 
884
 
-
 
885
function fix_latin($instr){
-
 
886
    
-
 
887
    $byte_map=array();
-
 
888
    init_byte_map();
-
 
889
    $ascii_char='[\x00-\x7F]';
-
 
890
    $cont_byte='[\x80-\xBF]';
-
 
891
    $utf8_2='[\xC0-\xDF]'.$cont_byte;
-
 
892
    $utf8_3='[\xE0-\xEF]'.$cont_byte.'{2}';
-
 
893
    $utf8_4='[\xF0-\xF7]'.$cont_byte.'{3}';
-
 
894
    $utf8_5='[\xF8-\xFB]'.$cont_byte.'{4}';
-
 
895
    $nibble_good_chars = "@^($ascii_char+|$utf8_2|$utf8_3|$utf8_4|$utf8_5)(.*)$@s";
895
function fix_latin($instr){
896
 
896
    if(mb_check_encoding($instr,'UTF-8'))return $instr; // no need for the rest if it's all valid UTF-8 already
-
 
897
    global $nibble_good_chars,$byte_map;
897
    if(mb_check_encoding($instr,'UTF-8'))return $instr; // no need for the rest if it's all valid UTF-8 already
898
    $outstr='';
898
    $outstr='';
899
    $char='';
899
    $char='';
900
    $rest='';
900
    $rest='';
901
    while((strlen($instr))>0){
901
    while((strlen($instr))>0){
902
        if(1==@preg_match($nibble_good_chars,$input,$match)){
902
        if(1==@preg_match($nibble_good_chars,$instr,$match)){
903
            $char=$match[1];
903
            $char=$match[1];
904
            $rest=$match[2];
904
            $rest=$match[2];
905
            $outstr.=$char;
905
            $outstr.=$char;
906
        }elseif(1==@preg_match('@^(.)(.*)$@s',$input,$match)){
906
        }elseif(1==@preg_match('@^(.)(.*)$@s',$instr,$match)){
907
            $char=$match[1];
907
            $char=$match[1];
908
            $rest=$match[2];
908
            $rest=$match[2];
909
            $outstr.=$byte_map[$char];
909
            $outstr.=$byte_map[$char];
910
        }
910
        }