将阿拉伯语音译成英语 - Wordpress

时间:2013-09-21 00:59:15

标签: php wordpress character

我想将阿拉伯字符转换为英文字符。

我想将wordpress中的帖子转换为英文字符。 并将其存储在像$ entitle这样的变量中。

我该怎么做?

可以请别人帮忙吗?

if ($this->registry->options['invetag_seotopic_ahmed_php'] AND $zwr_ahmedPHP == "show") {

    $en = str_split('{}DFL:"ZCV<>`qwertyuiop[]asdfghjkl;\'zxcvnm,./~QWERYIOPASHJKXNM?');

    $ar = str_split('<>][/:"~}{,.ذضصثقفغعهخحجدشسيبلاتنمكطئءؤرىةوزظًٌَُّإ÷×؛ٍِأـ،ْآ’؟');

    for ($ahmedPHP = 0; $ahmedPHP < count($seotopic_thread); $ahmedPHP++) {

        $inv_tmp = str_replace($ar, $en, $seotopic_thread[$ahmedPHP]);

        $inv_ar_tmp [] = str_replace(array('لا', 'لآ', 'لأ', 'لإ', '‘'), array('b', 'B', 'G', 'T', 'U'), $inv_tmp);
    }

    if (is_array($inv_ar_tmp)) {

        $invtag = implode(" ", $inv_ar_tmp);
        $invtag = '<hr size="1" style="color:#D1D1E1; background-color:#D1D1E1" />' . "<p class=\"alt2\" dir=\"ltr\" style=\"margin: 1px auto;  padding: 6px;border: 1px inset; width: 640px;height: 34px;text-align: left;overflow: auto\">" . $invtag . "</p>\n";
        $post[message] = $post[message] . $invtag;
    }
} 

1 个答案:

答案 0 :(得分:0)

你正在使用str_split来分割阿拉伯语多字节字符。 你需要使用多字节功能。

例如:

function multibyte_str_split($string) {
    $strlen = mb_strlen($string);
    while ($strlen) {
        $array[] = mb_substr($string, 0, 1, "UTF-8");
        $string = mb_substr($string, 1, $strlen, "UTF-8");
        $strlen = mb_strlen($string);
    }
    return $array;
}


$arb = <<<EOD
            <>][/:"~}{,.ذضصثقفغعهخحجدشسيبلاتنمكطئءؤرىةوزظًٌَُّإ÷×؛ٍِأـ،ْآ’؟
EOD;

$ar = multibye_str_split($arb);

编辑: 将此函数放在主题的'functions.php'文件中。

function arb2en_title($post=0)
{
  $text = get_the_title($post);


$arb_en_map=array ( 
'\\xd8\\xa1' => '\'', '\\xd8\\xa2' => '|', '\\xd8\\xa3' => '>',
'\\xd8\\xa4' => '&', '\\xd8\\xa5' => '<', '\\xd8\\xa6' => '}',
'\\xd8\\xa7' => 'A', '\\xd8\\xa8' => 'b', '\\xd8\\xa9' => 'p',
'\\xd8\\xaa' => 't', '\\xd8\\xab' => 'v', '\\xd8\\xac' => 'j',
'\\xd8\\xad' => 'H', '\\xd8\\xae' => 'x', '\\xd8\\xaf' => 'd',
'\\xd8\\xb0' => '*', '\\xd8\\xb1' => 'r', '\\xd8\\xb2' => 'z',
'\\xd8\\xb3' => 's', '\\xd8\\xb4' => '$', '\\xd8\\xb5' => 'S',
'\\xd8\\xb6' => 'D', '\\xd8\\xb7' => 'T', '\\xd8\\xb8' => 'Z',
'\\xd8\\xb9' => 'E', '\\xd8\\xba' => 'g', '\\xd9\\x80' => '_',
'\\xd9\\x81' => 'f', '\\xd9\\x82' => 'q', '\\xd9\\x83' => 'k',
'\\xd9\\x84' => 'l', '\\xd9\\x85' => 'm', '\\xd9\\x86' => 'n',
'\\xd9\\x87' => 'h', '\\xd9\\x88' => 'w', '\\xd9\\x89' => 'Y',
'\\xd9\\x8a' => 'y', '\\xd9\\x8b' => 'F', '\\xd9\\x8c' => 'N',
'\\xd9\\x8d' => 'K', '\\xd9\\x8e' => 'a', '\\xd9\\x8f' => 'u',
'\\xd9\\x90' => 'i', '\\xd9\\x91' => '~', '\\xd9\\x92' => 'o',
'\\xd9\\xb0' => '`', '\\xd9\\xb1' => '{', 
        );

foreach($arb_en_map as $key=>$value)
{
    $text=preg_replace("/$key/",$value,$text);
}
return  htmlentities($text);

}

在你的主题中,你可以通过拨打电话获得英文标题  arb2en_title()函数。

例如:

echo arb2en_title();

注意:我使用了buckwalter音译图表。

http://www.ldc.upenn.edu/myl/morph/buckwalter.html

EDIT ::

用于arbic键盘映射,如以下链接: http://elfnoon.com/demo/maps.html

用这个替换arb_en_map数组:

$arb_en_map=array(
            'د'=>']',
           'ج'=>'[',
           'ح'=>'p',
           'خ'=>'o',
           'ه'=>'i',
           'ع'=>'u',
           'غ'=>'y',
           'ف'=>'t',
           'ق'=>'r',
           'ث'=>'e',
           'ص'=>'w',
           'ض'=>'q',
           'ش'=>'a',
           'س'=>'s',
           'ي'=>'d',
           'ب'=>'f',
           'ل'=>'g',
           'ا'=>'h',
           'ت'=>'j',
           'ن'=>'k',
           'م'=>'l',
           'ك'=>';',
           'ط'=>'\'',
           'ظ'=>'/',
           'ز'=>'.',
           'و'=>',',
           'ة'=>'m',
           'ى'=>'n',
           'ل'=>'b',
           'ر'=>'v',
           'ؤ'=>'c',
           'ء'=>'x',
           'ئ'=>'z',
           'إ'=>'Y',
           'لإ'=>'T',
           'لأ'=>'G',
           'أ'=>'H',
           'لآ'=>'B',
           'آ'=>'N'
);

或者你可以使用十六进制映射数组,两者都是相同的:

$arb_en_map=array ( 
 '\\xd8\\xaf' => ']', '\\xd8\\xac' => '[', '\\xd8\\xad' => 'p',
 '\\xd8\\xae' => 'o', '\\xd9\\x87' => 'i', '\\xd8\\xb9' => 'u',
 '\\xd8\\xba' => 'y', '\\xd9\\x81' => 't', '\\xd9\\x82' => 'r',
 '\\xd8\\xab' => 'e', '\\xd8\\xb5' => 'w', '\\xd8\\xb6' => 'q',
 '\\xd8\\xb4' => 'a', '\\xd8\\xb3' => 's', '\\xd9\\x8a' => 'd',
 '\\xd8\\xa8' => 'f', '\\xd9\\x84' => 'B', '\\xd8\\xa7' => 'h',
 '\\xd8\\xaa' => 'j', '\\xd9\\x86' => 'k', '\\xd9\\x85' => 'l',
 '\\xd9\\x83' => ';', '\\xd8\\xb7' => '\'', '\\xd8\\xb8' => '/',
 '\\xd8\\xb2' => '.', '\\xd9\\x88' => ',', '\\xd8\\xa9' => 'm', 
 '\\xd9\\x89' => 'n', '\\xd8\\xb1' => 'v', '\\xd8\\xa4' => 'c', 
 '\\xd8\\xa1' => 'x', '\\xd8\\xa6' => 'z', '\\xd8\\xa5' => 'Y',
 '\\xd8\\xa3' => 'H', '\\xd8\\xa2' => 'N',
 );