root - 2 months ago 5x
PHP Question

# convert Persian/Arabic numbers to English numbers

How can I convert Persian/Arabic numbers to English numbers with a simple function ?

Persian/Arabic numbers:

``````۰   //  -> 0
۱   //  -> 1
۲   //  -> 2
۳   //  -> 3
۴   //  -> 4
۵   //  -> 5
۶   //  -> 6
۷   //  -> 7
۸   //  -> 8
۹   //  -> 9
``````

numbers over the unicode :

``````\$num0="&#1776;";
\$num1="&#1777;";
\$num2="&#1778;";
\$num3="&#1779;";
\$num4="&#1780;";
\$num5="&#1781;";
\$num6="&#1782;";
\$num7="&#1783;";
\$num8="&#1784;";
\$num9="&#1785;";
``````

MyFunction / Converting numbers to English:

``````    function Convertnumber2english(\$srting) {
\$num0="0";
\$num1="1";
\$num2="2";
\$num3="3";
\$num4="4";
\$num5="5";
\$num6="6";
\$num7="7";
\$num8="8";
\$num9="9";

\$stringtemp="";
\$len=strlen(\$srting);
for(\$sub=0;\$sub<\$len;\$sub++){
if(substr(\$srting,\$sub,1)=="۰")\$stringtemp.=\$num0;
elseif(substr(\$srting,\$sub,1)=="۱")\$stringtemp.=\$num1;
elseif(substr(\$srting,\$sub,1)=="۲")\$stringtemp.=\$num2;
elseif(substr(\$srting,\$sub,1)=="۳")\$stringtemp.=\$num3;
elseif(substr(\$srting,\$sub,1)=="۴")\$stringtemp.=\$num4;
elseif(substr(\$srting,\$sub,1)=="۵")\$stringtemp.=\$num5;
elseif(substr(\$srting,\$sub,1)=="۶")\$stringtemp.=\$num6;
elseif(substr(\$srting,\$sub,1)=="۷")\$stringtemp.=\$num7;
elseif(substr(\$srting,\$sub,1)=="۸")\$stringtemp.=\$num8;
elseif(substr(\$srting,\$sub,1)=="۹")\$stringtemp.=\$num9;
else \$stringtemp.=substr(\$srting,\$sub,1);
}
return   \$stringtemp;
}
``````

``````function convert(\$string) {
You can use the unicode instead of the characters in `\$persian` (I think).