3

以下のコードを書きましたが、うまくいきません:

$t = "۰۱۲۳۴۵۶۷۸۹٤٥٦";
$correct = array("0","1","2","3","4","5","6","7","8","9","4","5","6");
$wrong = array("٠","١","٢","٣","٤","٥","٦","٧","٨","٩","۴","۵","۶");
echo $t = str_replace($wrong,$correct, $t);

そして結果は正しくない

۰۱۲۳456۷۸۹۰۱۲۳456۷۸۹456

スタックと同じ質問を検索しますが、その回答は役に立ちません。

4

4 に答える 4

2

このコードを使用してください:-

$t = "۰۱۲۳٤٥٦";
$text = preg_replace(
            array("٠","١","٢","٣","٤","٥","٦",),
            array("0","1","2","3","4","5","6",),
            $t );
于 2012-11-20T07:00:57.363 に答える
1

問題については何も知りませんが、この関数を試してアイデアを実装することができます。

//converts the numbers into the persian's number
function persianNum($srting)
{
    $num0="۰";
    $num1="۱";
    $num2="۲";
    $num3="۳";
    $num4="۴";
    $num5="۵";
    $num6="۶";
    $num7="۷";
    $num8="۸";
    $num9="۹";

    $stringtemp="";
    $len=strlen($srting);
    for($sub=0;$sub<$len;$sub++)
    {
         if(substr($srting,$sub,1)=="0")$stringtemp.=$num0;
         elseif(substr($srting,$sub,1)=="1")$stringtemp.=$num1;
         elseif(substr($srting,$sub,1)=="2")$stringtemp.=$num2;
         elseif(substr($srting,$sub,1)=="3")$stringtemp.=$num3;
         elseif(substr($srting,$sub,1)=="4")$stringtemp.=$num4;
         elseif(substr($srting,$sub,1)=="5")$stringtemp.=$num5;
         elseif(substr($srting,$sub,1)=="6")$stringtemp.=$num6;
         elseif(substr($srting,$sub,1)=="7")$stringtemp.=$num7;
         elseif(substr($srting,$sub,1)=="8")$stringtemp.=$num8;
         elseif(substr($srting,$sub,1)=="9")$stringtemp.=$num9;
         else $stringtemp.=substr($srting,$sub,1);
    }
return   $stringtemp;

}
//end convert function
于 2012-11-20T07:58:49.267 に答える
1

'mb_str_replace()'関数を試してください。

http://php.net/manual/en/ref.mbstring.php

于 2012-11-20T06:43:27.107 に答える