<?php class rakam { var $metin; function rakam() { $this->veri = array(1=>'satu','dua','tiga','empat','lima','enam','tujuh','delapan','sembilan'); $this->sayi= array(1000000000,1000000,1000,100,10,1); $this->birim = array('milyar','juta','ribu','ratus','puluh',''); } function yaz($n) { $this->metin=null; $i=0; while($n!=0){ $say = (int)($n/$this->sayi[$i]); if($say>=10){ $this->metin .= $this->yaz($say). " ".$this->birim[$i]." "; }else if($say > 0 && $say < 10) $this->metin .= $this->veri[$say] . " ".$this->birim[$i]." "; $n -= $this->sayi[$i] * $say; $i++; } $this->metin = preg_replace("/satu puluh (\w+)/i","\\1 belas",$this->metin); $this->metin = preg_replace("/satu (ribu|ratus|puluh|belas)/i","se\\1",$this->metin); $ciftara=array_values(array_filter(explode(" ",$this->metin))); if(@$ciftara[0] == @$ciftara[1]){ return substr($this->metin, strlen($ciftara[0]), strlen($this->metin))."<br>"; }elseif((@$ciftara[0].@$ciftara[1]) == (@$ciftara[2].@$ciftara[3])){ return substr($this->metin, strlen($ciftara[0])+strlen($ciftara[1])+1, strlen($this->metin)); }elseif((@$ciftara[0].@$ciftara[1].@$ciftara[2]) == (@$ciftara[3].@$ciftara[4].@$ciftara[5])){ return substr($this->metin, strlen($ciftara[0])+strlen($ciftara[1])+strlen($ciftara[2])+2, strlen($this->metin)); }elseif((@$ciftara[0].@$ciftara[1].@$ciftara[2].@$ciftara[3]) == (@$ciftara[4].@$ciftara[5].@$ciftara[6].@$ciftara[7])){ return substr($this->metin, strlen($ciftara[0])+strlen($ciftara[1])+strlen($ciftara[2])+strlen($ciftara[3])+3, strlen($this->metin)); }else{ return $this->metin; } } } $sayi = new rakam; echo $sayi->yaz(12415); ?>
Çıktısı
dua belas ribu empat ratus lima belas