Jump to content

Entering Numbers in Different Formats


J.Silver

Recommended Posts

I am writing an e-commerce website in multiple languages, including some eastern languages that have numerals in their languages different than the Arabic numerals used worldwide. To give an example:

 

Arabic Numerals: 0  1  2  3,…

Urdu Numerals: ٣  ٢  ١  ٠

 

In countries using such Urdu, Persian, etc. numbers PC keyboards are configured differently, some keyboards are configured to enter the Arabic numerals, while the majority of keyboards are configured to enter their native numbers. This invited a need to design my website so that credit card numbers, address and phone numbers can accept different forms of numerals. Since orders, users, … tables should have one form of numbers only, I am thinking of a script in which the user can enter credit card numbers, address and phone numbers in multiple form numbers and then all forms are translated in the tables to be in one form only, Arabic numerals. I would appreciate sharing any ideas, scripts, etc. to achieve this.

 

Link to comment
Share on other sites

well the first thing that comes to my mind is to map the characters and use str_replace to convert them..

 

$map_arr = array("١ " => "a", "٢  " => "b");
$string = "text that you want to replace the characters in";
$string = str_replace(array_keys($map_array), array_values($map_arr),$string);

 

if you will need to use this many times.. i would recommend storing it into a function..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.