Last active
November 19, 2016 16:26
-
-
Save mehmeteminkartal/5cb685649c4f3c92cc59af67fd496b95 to your computer and use it in GitHub Desktop.
PHP number to string (Turkish)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function numtostr($num, $glue = " ") { | |
$c = array( | |
array("", "bir", "iki", "üç", "dört", "beş", "altı", "yedi", "sekiz", "dokuz"), | |
array("", "on", "yirmi", "otuz", "kırk", "elli", "altmış", "yetmiş", "seksen", "doksan"), | |
); | |
$b = array("", "bin", "milyon", "milyar", "trilyon", "katrilyon", "kentilyon"); | |
$ret = ""; | |
$basamaklar = explode(".", number_format((String) ($num), 0, ",", ".")); | |
$len = strlen((String) ($num)); | |
$o = array(); | |
($num < 0 ? $o[] = "eksi" : false); | |
if($num == 0){ | |
return "sıfır"; | |
} | |
foreach ($basamaklar as $key => $basamak) { | |
if ((int) $basamak == 0) { | |
continue; | |
} | |
$n = str_split($basamak); | |
foreach ($n as $k => $q) { | |
if (count($n) - 1 - $k == 2 && $q != 0) { | |
($q != 1 && $c[0][$q] != "" ? $o[] = $c[0][$q] : false); | |
$o[] = "yüz"; | |
} else { | |
$y = count($n) - 1 - $k; | |
if($k != 0 || $y != 0 || $q != 1) { | |
((isset($c[$y]) && isset($c[$y][$q])&& $c[$y][$q] != "") ? ($o[] = $c[$y][$q]) : false); | |
} | |
} | |
} | |
$r = $b[count($basamaklar) - 1 - $key]; | |
($r != "" ? $o[] = $r : false); | |
} | |
return implode($glue,$o); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment