Word of the Day

Monday, April 7, 2008

GemCoverter converts Arabic numbers into Hebrew Numerals

So, I hope this PHP script is a great relief for all those who have difficulty switching between Arabic numbers and Hebrew Numerals.

Please add "< ? p,h,p" before the first IF clause.

/*Copyright: Sparnai; Date 2008-04-08*/

[noparse]
if($_POST["in"] == null){
print "Please enter a number.";
}elseif(preg_match("/^[1-9][0-9]{0,2}$/",$_POST["in"])){
$in = $_POST["in"];
}else{
die("Wrong input!");
}



if($in <= 999 and $in >= 900){$_900='תתק';}
elseif($in <= 899 and $in >= 800){$_900='תת';}
elseif($in <= 799 and $in >= 700){$_900='תש';}
elseif($in <= 699 and $in >= 600){$_900='תר';}
elseif($in <= 599 and $in >= 500){$_900='תק';}
elseif($in <= 499 and $in >= 400){$_900='ת';}
elseif($in <= 399 and $in >= 300){$_900='ש';}
elseif($in <= 299 and $in >= 200){$_900='ר';}
elseif($in <= 199 and $in >= 100){$_900='ק';}
else{$_900='';}



$_in099 = substr($in,-2);

if($_in099 <= 99 and $_in099 >= 90){$_090 = 'צ';}
elseif($_in099 <= 89 and $_in099 >= 80){$_090 = 'פ';}
elseif($_in099 <= 79 and $_in099 >= 70){$_090 = 'ע';}
elseif($_in099 <= 69 and $_in099 >= 60){$_090 = 'ס';}
elseif($_in099 <= 59 and $_in099 >= 50){$_090 = 'נ';}
elseif($_in099 <= 49 and $_in099 >= 40){$_090 = 'מ';}
elseif($_in099 <= 39 and $_in099 >= 30){$_090 = 'ל';}
elseif($_in099 <= 29 and $_in099 >= 20){$_090 = 'כ';}
elseif($_in099 <= 19 and $_in099 >= 10){$_090 = 'י';}
else{$_090 = '';}



$_in009 = substr($in,-1);

if($_in009 == 9){$_009 = 'ט';}
elseif($_in009 == 8){$_009 = 'ח';}
elseif($_in009 == 7){$_009 = 'ז';}
elseif($_in009 == 6){$_009 = 'ו';}
elseif($_in009 == 5){$_009 = 'ה';}
elseif($_in009 == 4){$_009 = 'ד';}
elseif($_in009 == 3){$_009 = 'ג';}
elseif($_in009 == 2){$_009 = 'ב';}
elseif($_in009 == 1){$_009 = 'א';}
else{$_009 = '';}



if($_in099 == 16){$_099 = 'טז';}
elseif($_in099 == 15){$_099 = 'טו';}
else {$_099 = $_090.$_009;}



$_999 = $_900.$_099;

if(strlen($_999) > 7){
$_999g = substr($_999,0,strlen($_999)-7).'״'.substr($_999,-7);}
else{
$_999g = $_999;}

if($in > 0){print 'The Hebrew numeral for '.number_format($in).' is:
'.$_999.'
'.$_999g;}
else{print "";}

?>[/noparse]

No comments: