0

遇到这个阿拉伯UNICODE基本区文字转换成UNICODE扩区码的问题,但不成功。我有下面的代码,帮我看看。这个转换不正确。是什么原因

<?
header("content-type: text/html; charset=utf-8");
    mb_http_output( "UTF-8" );
function Un2k($Un){
     $Uk[0] ="چېتيڭپسىقكلشغبنمفگخجروۈزۋداەژۆۇﻻﺋھ";
        $Uk[1] = "ﭺﯥﺕﻱﯓﭖﺱﻯﻕﻙﻝﺵﻍﺏﻥﻡﻑﮒﺥﺝﺭﻭﯛﺯﯞﺩﺍﻩﮊﯙﯗﻻ∥∥";
        $Uk[2] = "ﭼﯦﺗﻳﯕﭘﺳﯨﻗﻛﻟﺷﻏﺑﻧﻣﻓﮔﺧﺟ∥∥∥∥∥∥∥∥∥∥∥∥ﺋﮬ";
        $Uk[3] = "ﭻﯥﺖﻲﯔﭗﺲﻰﻖﻚﻞﺶﻎﺐﻦﻢﻒﮓﺦﺞﺮﻮﯜﺰﯟﺪﺎﻪﮋﯚﯘﻼ∥∥";
        $Uk[4] = "ﭽﯧﺘﻴﯖﭙﺴﯩﻘﻜﻠﺸﻐﺒﻨﻤﻔﮕﺨຠ∥∥∥∥∥∥∥∥∥∥∥∥ﺌﮭ";

        $Un2K1 = "";
        $i ;
        $ix ;
        $s ;
        $s_ ;
        $_s ;
        $L ;
        $_ix ;
        $ix_ ;
        $_TF ;
        $TF_ ;
        $L = mb_strlen($Un,"utf8");

        for ($i=1;$i<$L;$i++){
            $s = mb_substr($Un, $i, 1,"utf8");

            if($i!=$L){ $s_ = mb_substr($Un, $i + 1, 1,"utf8");}else{$s_="";}
            if($i>1){ $_s = mb_substr($Un, $i - 1, 1,"utf8");}else{$_s="";}
            $ix = mb_strpos($Uk[0], $s);
             if(empty($ix)){
                 //
               if($i!=$L){$ix_ = mb_strpos($Uk[0], $s_);}else{$ix_="";}
               if($i>1){$_ix = mb_strpos($Uk[0], $_s);}else{$_ix="";}
               //
                 if($_ix == 0 or mb_strpos("روۈزۋداەژۆۇ", $_s) != 0){
                      $_TF = false;
                 }elseif(mb_substr($Uk[2], $_ix, 1,"utf8") != "." or mb_substr($Uk[4], $_ix, 1,"utf8") != "."){
                     $_TF = true;
                 }
                 if($ix==0){
                    $TF_ = false;
                 }elseif(mb_substr($Uk[3], $ix_, 1,"utf8") != "." or mb_substr($Uk[4], $ix_, 1,"utf8") != "."){
                     $_TF = true;
                 }
                 if(mb_strpos("چېتيڭپسىقكلشغبنمفگخج", $s) != 0){
                     if($_TF == false and $TF_ == false){
                         $Un2K1 = $Un2K1.mb_substr($Uk[1], $ix, 1,"utf8");
                     }elseif($_TF == true and $TF_ == false){
                         $Un2K1 = $Un2K1.mb_substr($Uk[3], $ix, 1,"utf8");
                     }elseif($_TF == false and $TF_ == true){
                         $Un2K1 = $Un2K1.mb_substr($Uk[2], $ix, 1,"utf8");
                     }

                 }elseif(mb_strpos("روۈزۋداەژۆۇ", $s) != 0){
                     if($_TF == false){
                        $Un2K1 = $Un2K1.mb_substr($Uk[1], $ix, 1,"utf8");
                     }elseif($_TF == true){
                        $Un2K1 = $Un2K1.mb_substr($Uk[3], $ix, 1,"utf8");
                     }
                 }else{
                     if($TF_ == false){
                        $Un2K1 = $Un2K1.mb_substr($Uk[4], $ix, 1,"utf8");
                     }elseif($TF_ == true){
                        $Un2K1 = $Un2K1.mb_substr($Uk[2], $ix, 1,"utf8");
                     }
                 }

             }else{
                 $Un2K1 = $Un2K1.$s;
             }
        }
        $Un2K1 = str_ireplace("ﻟﺎ", "ﻻ",$Un2K1);
        $Un2K1 = str_ireplace("(", "<!>",$Un2K1);
        $Un2K1 = str_ireplace(")", "(",$Un2K1);
        $Un2K1 = str_ireplace("<!>", ")",$Un2K1);
        $Un2K1 = str_ireplace("«", "<!>",$Un2K1);
        $Un2K1 = str_ireplace("»", "«",$Un2K1);
        $Un2K1 = str_ireplace("<!>", "»",$Un2K1);
        $Un2K1 = str_ireplace("", "",$Un2K1);
        $Un2K1 = str_ireplace("", "",$Un2K1);
        //$Un2K1 = santatur2($Un2K1);

        return  $Un2K1;
}


function santatur2($str) {  
    $len = mb_strlen($str, 'UTF-8');  
    $string = '';  
    for ($i = $len - 1; $i >= 0; $i--) {  
       $string .= mb_substr($str, $i, 1, 'UTF-8');                                                           
    }  
    return $string;  
} 


















?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>

<body>

<?

echo(Un2k("شاكىر"));


?>

</body>

</html>
4

1 回答 1

0

你为什么不使用mb_convert_encoding()。在您的情况下,它应该非常有用。

这是一个将 EUC-JP 转换为 UTF-7的示例:

$str = mb_convert_encoding($str, "UTF-7", "EUC-JP");

支持的编码列表

于 2012-05-19T08:52:40.633 回答