Skip to content

Instantly share code, notes, and snippets.

@mehmeteminkartal
Last active November 19, 2016 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mehmeteminkartal/5cb685649c4f3c92cc59af67fd496b95 to your computer and use it in GitHub Desktop.
Save mehmeteminkartal/5cb685649c4f3c92cc59af67fd496b95 to your computer and use it in GitHub Desktop.
PHP number to string (Turkish)
<?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