Transliterate arabic characters into english – WordPress

I want to convert arabic characters into english characters.

I want to convert the tile of post in wordpress and transliterate into english characters.
and store it in a variable like $entitle.

Read More

how can i do it?

Can please someone help?

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;
    }
} 

Related posts

Leave a Reply

1 comment

  1. you are using str_split fro spliting the arabic multi byte charactors.
    you need to use a multibyte function.

    eg:

    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);
    

    EDIT:
    put this function in the ‘functions.php’ file in your theme.

    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);
    
    }
    

    in your theme, you can get the title in english by calling the
    arb2en_title() function.

    eg:

    echo arb2en_title();
    

    Note: i have used the buckwalter transliteration chart.

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

    EDIT::

    for arbic key board mapping like in this link:
    http://elfnoon.com/demo/maps.html

    replace the arb_en_map array with this:

    $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'
    );
    

    or you can use the hex mapping array, both are same:

    $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',
     );