unicode - how to change to english number to nepali number in php -


in project have change english numerals nepali 1 upto 2 digits. e.g. if enter 1 should return १ , if enter 41 should return ४१ , have store ४१ in db , show in front end. how this? tried use "font-family: preeti;" when getting nepali numerals gives ४ , not १. when use below function gives ४ instead of १. how solve this?

function convertnos($nos){   switch($nos){     case"०":return 0;     case"१":return 1;     case"२":return 2;     case"३":return 3;     case"४":return 4;     case"५":return 5;     case"६":return 6;     case"७":return 7;     case"८":return 8;     case"९":return 9;     case"0":return"०";     case"1":return"१";     case"2":return"२";     case"3":return"३";     case"4":return"४";     case"5":return"५";     case"6":return"६";     case"7":return"७";     case"8":return"८";     case"9":return"९";    } } 

any help/suggestion welcome.thanks in advance.

/* set internal character encoding utf-8 */    header('content-type: text/html; charset=utf-8');    mb_internal_encoding("utf-8");  // array of nepali number representations function convertnos($nos){     $n = '';   switch($nos){     case "०": $n = 0; break;     case "१": $n = 1; break;     case "२": $n= 2; break;     case "३": $n = 3; break;     case "४": $n = 4; break;     case "५": $n = 5; break;     case "६": $n = 6; break;     case "७": $n = 7; break;     case "८": $n = 8; break;     case "९": $n = 9; break;     case "0": $n = "०"; break;     case "1": $n = "१"; break;     case "2": $n = "२"; break;     case "3": $n = "३"; break;     case "4": $n = "४"; break;     case "5": $n = "५"; break;     case "6": $n = "६"; break;     case "7": $n = "७"; break;     case "8": $n = "८"; break;     case "9": $n = "९"; break;    }    return $n; }  $num = 0; // number // replace whatever you're using number if (isset($_get['number'])) $num = strip_tags($_get['number']);  /* convert number (could string of unicode,   * not digit) string , split  * array of characters.   */  $str_num = preg_split('//u', ("". $num), -1); // not explode('', ("". $num))      // each item in exploded string, retrieve nepali equivalent or vice versa.     $out = '';     $out_arr = array_map('convertnos', $str_num);     $out = implode('', $out_arr);     print($out);     // make sure php file saved utf-8 text file 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -