Hi everyone,

Can you please let me know why I am getting error on populating Persian(Arabic)Numbers?!
I have saved the php file as "Uncode in UTF-8" format which can display the dropdown list in a HTML correctly but when I want to retrieve them in PHP I encountered with following errors
Errors:
(!) Notice: Use of undefined constant ١‎ - assumed '١‎' in C:\wamp\www\PHPCode\Test.php on line 14
(!) Notice: Use of undefined constant ٣١‎ - assumed '٣١' in C:\wamp\www\PHPCode\Test.php on line 14
* ١ = is a Persian number equal to 1
* ٣١ = is a Persian number equal to 31

<?php

$numberArray = array();

for ($i = ١‎; $i < ٣١; $i++)
{
  $numberArray[] = $i;
 } 
  for ($i = 0; $i < sizeof($numberArray); $i++) {
         echo "$numberArray[$i]"."<br />";
	}
?>

I really appreciate your time regarding this.

PHP can only read its native language.

<?php

$numberArray = array();

for ($i = 1‎; $i < 31; $i++)
{
  $numberArray[] = $i;
 } 
  for ($i = 0; $i < sizeof($numberArray); $i++) {
         echo $numberArray[$i]."<br />";
	}
?>

Thanks for your reply
Somehow I do not agree with you since php is supporting the other languages like Farsi and I can easily populate all Farsi(Persian) alphabetical characters in PHP.The only problem is working with numbers!

Thanks for your reply
Somehow I do not agree with you since php is supporting the other languages like Farsi and I can easily populate all Farsi(Persian) alphabetical characters in PHP.The only problem is working with numbers!

If you like I shall give you a little history lesson that explains it. It all started in the late 1970's when scientists were finding a way to display characters on a monitor (strings) for command line operating systems like Unix and dos. Back then all they had were binary codes that represented the flow of electrons going along the circuits. But the only problem with that was they couldn't do it or at least easily unless they placed a set of transistors in a specific order generating the electrons. So the scientists had to tackle the bigger problem first before they could get to displaying characters. This is when software was invented. To invent software what scientists would have to do is assign numbers to binary codes. For example 0=0 1=1 2=10 3=11 4=100 5=101 6=110 7=111 and so on to represent the electrons in the circuit. The scientists then tout the computer how to do mathematics with the numbers/integers allowing for graphical interfaces and 3d games to be possible later on. After mathematics had been invented on a binary level, characters were invented the same way except characters were and still are today just meaningless symbols assigned to a binary code. These symbols at first went from 0 to 127 but later extended from 0 to 255. They today represent an 8 bit binary code and to a computer are just another type of number without the math. To us they are text. However, as per the Persian/Arabic numbers in computing, they are symbols (not numbers) there by the computer cannot interpret them as numbers and cannot do mathematics on them. That is the conclusion.

Member Avatar
diafol

Personally, I'd do this:

$farsi = array('۰','۱','۲','۳','۴','۵','۶','۷','۸','۹');
$num = range(0,9);
$numberArray = array();
 
for ($i = 1; $i < 31; $i++){
   $n = str_replace($num,$farsi,$i);
   $numberArray[] = $n;
} 
for ($i = 0; $i < sizeof($numberArray); $i++) {
   echo "$numberArray[$i]"."<br />";
}

If you're getting 1 and 31 from a form where you're using farsi numbers, just do the reverse conversion:

$first_num = (int) str_replace($farsi,$num,$_POST['first']);
$sec_num = (int) str_replace($farsi,$num,$_POST['second']);

That last bit is off the top of my head, so don't know if it would work.

for ($i = $first_num; $i < $sec_num; $i++){
   $n = str_replace($num,$farsi,$i);
   $numberArray[] = $n;
}

I don't understand why you've got 2 loops though. One should be enough:

$farsi = array('۰','۱','۲','۳','۴','۵','۶','۷','۸','۹');
$num = range(0,9);
for ($i = 1; $i < 31; $i++){
   echo str_replace($num,$farsi,$i) . "<br />";
}
commented: Perfect approch +3

Awesome!
Thanks ardav, This is exactly what I was looking for.
Once again thanks for your time

Member Avatar
diafol

Awesome!
Thanks ardav, This is exactly what I was looking for.
Once again thanks for your time

You're welcome. Took me some time to find the Farsi numerals though :)