tags:

views:

170

answers:

4

How can i convert English numbers being retrieved from the database to Arabic numeral symbols in PHP.

EDIT: Here're some examples of what Arabic numerals look like. I live in an Arab country, so please don't go around explaining to me what Arabic numerals look like. If you can help, good and well. I don't need bogus ideas.

http://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Arabic_numerals-en.svg/500px-Arabic_numerals-en.svg.png

A: 

Are you trying to convert e.g. Sixty-nine to تسعة وستون? Try if you can call the Google Translate service or another translation service. Otherwise, you should write your own numeral parser and use your knowledge of the Arabic language to translate it to Arabic. (But using a translation service would be a lot easier.) (Then again, PHP might already have a function that writes out numbers and digits in the proper way.)

Workshop Alex
No, i need to convert 10 to it's arabic counterpart. I have no knowledge of the Arabic language. That's a stupid suggestion anyway.
gAMBOOKa
@gAMBOOKa: Do you mean romans like `I, II , III, IV`?
Sarfraz
No, i mean 1, 2, 3, 4.... I found plenty of Roman numeral classes as well. I know google too!
gAMBOOKa
Then don't use "numerals". Numerals are the words that describe numbers. 54 is a number, fifty-four is a numeral.
Workshop Alex
It's funny isn't it, the arabic number for 10 is 10. That's because we actually use arabic numbers throughout most of the world, and certainly in the world of mathematics
Mark Baker
No Mark, we use Arabic numbers, not numerals! :-)
Workshop Alex
Numbers in arabic are exactly the same as in any other language(well.. in morden language anyway). In fact the, if i remember history correctly, the numbers we use today (1, 2, 3 etc) come from middle east in the first place. And check out some random saudi arabian newspaper: http://www.alriyadh.com/notice something familiari there, perhaps?
Zayatzz
@Workshop Alex: *sigh* no, we use arabic numerals: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9
hop
@Mark: http://upload.wikimedia.org/wikipedia/commons/thumb/d/d8/EgyptphoneKeypad.jpg/220px-EgyptphoneKeypad.jpg
gAMBOOKa
@hop, the definition of numeral is: "specific words in a natural language that represent numbers." Your example are just numbers. It's a BIG difference. Then again, a lot of people are confused by this.
Workshop Alex
@Workshop Alex: you confuse linguistics and writing. there are no "arabic numbers" and "chinese numbers" and "english numbers" -- numbers are the same everywhere in the universe.
hop
What @gAMBOOKa seems to be meaning is *eastern arabic/indic* numerals: http://en.wikipedia.org/wiki/Eastern_Arabic_numerals
Pekka
@Pekka: aka Arabic Numerals!
gAMBOOKa
@gAMBOOKa **no**. Arabic numerals are `12345....` see http://en.wikipedia.org/wiki/Arabic_numerals
Pekka
@Pekka: Wikipedia is not always accurate http://en.wikipedia.org/wiki/Arabic_script#Numerals
gAMBOOKa
@hop, there are arabic and chinese numeral symbols. Technically, 0123456789 are also numeral symbols but these are so common worldwide that they are referred to as numbers. Or, to be more precise, those numbers are West Arabic numeral symbols. (Thus not even english numerals!)
Workshop Alex
@gambooka `There are two kinds of numerals used in Arabic writing; standard numerals(predominant in the Arab World), and Eastern Arabic numerals (used in Iran, Afghanistan, Pakistan and India)` what is not accurate here? What you are looking for does not seem to be referred to as "Arabic Numeral"s in any case.
Pekka
@Workshop Alex: your worldview is narrow it's not even funny. in german those are commonly referred to as "Ziffern" (numerals) not "Zahlen" (numbers), so what's your point again?
hop
I've been to Kuwait, Saudia and the UAE. And what you refer to as Eastern Arabic Numerals are predominant in these countries. You see them as phone numbers on shops, street numbers, highway speed limits, government documents, everywhere.
gAMBOOKa
@gAMBOOKa I'm pretty sure the global consensus is that "Arabic Numerals" are 1234567890. They are technically to be called "western arabic" to be exact, but they still are arabic. Anyway, you would just have had to give one full example of what you want - it would have prevented all this discussion.
Pekka
True! But interesting discussion anyway.
gAMBOOKa
@hop, the question wasn't about German and I'm not interested in any German linguistics. Besides, numeral would translate to "Zahlennamen", not just "Zahlen". And "Ziffer" would translate to "digit". And why do we continue to discuss something this trivial anyways? Read a dictionary! ;-)
Workshop Alex
@gAMBOOKa yes, very interesting for me as well! I didn't know about eastern arabic numerals at all. Learned something.
Pekka
@Workshop Alex: i give up. it's obvious that you don't even _read_ what i _write_.
hop
@hop, and you don't read what I write. You're confusing Numerals (zahlennamen) with numbers (zahlen) while there is a clear difference. (I fixed the confusion in the original Q, btw.) I talk about numerals, you talk about numbers. See the difference?
Workshop Alex
A: 

Perhaps you're looking for a resource such as this?

http://vegasociety.com/arabic/numbers.html

Anax
+3  A: 

If you are referring to what Wikipedia calls eastern arabic / indic numerals, a simple replace operation should do.

$standard = array("0","1","2","3","4","5","6","7","8","9");
$east_arabic = array(Insert numerals - my browser crashes when copy + pasting)

$string = str_replace($standard , $east_arabic , $string);

Update: You'll probably have to reverse the number using strrev() to take into account Arabic's right-to-left nature. I have no experience with Arabic localization so I don't know whether that will bring any additional problems.

Pekka
But will that take care of rtl nature of the arabic lanugage? for instance, will 123 show up as ٣٢١
gAMBOOKa
@gAMBOOKa nope - you'd have to turn it around using `strrev()`: http://www.php.net/manual/en/function.strrev.php
Pekka
Ahh perfect! That should work. Shukran Habibi!
gAMBOOKa
$east_arabic = array("०","१","२","३","४","५","६","७","८","९"); My browser did not crash...
Workshop Alex
A: 

I would suggest u to try using resource file for different language especially if the contents are known. Example: 2 file language files, 1 named language_EN, another language_AR where langauge_EN is to store the values in english, and language_AR for arabic.

so for instance u want store the number "1"

in langauge_EN, do something like this. number.one=1

then in langauge_AR, (pretend x is the number "1" in arabic, but I guess unicode is preferred) number.one=x

so after u retrieve from database and knowing that it is number, your raw result comes out to be "one".

so use number.+[result from database] to load from the langauage_AR This method is quite widely used in webpages which allow toggling of language. So at any time u need to convert back to english, just change back to language_EN. This works not only for number. Gd Luck

C_Rance