gurumutant

Class Terbilang by Huda M. Elmatsani

Jan 10th, 2022
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. *
  5. * Class : Terbilang
  6. * Spell quantity numbers in Indonesian or Malay Language
  7. *
  8. *
  9. * author: huda m elmatsani
  10. * 21 September 2004
  11. * freeware
  12. *
  13. * example:
  14. * $bilangan = new Terbilang;
  15. * echo $bilangan -> eja(12415);
  16. * result: dua belas ribu empat ratus lima belas
  17. *
  18. *
  19. */
  20.  
  21. class Terbilang {
  22.  
  23.     function __construct() {
  24.         $this->dasar = array(1=>'satu','dua','tiga','empat','lima','enam',
  25.         'tujuh','delapan','sembilan');
  26.  
  27.         $this->angka = array(1000000000,1000000,1000,100,10,1);
  28.         $this->satuan = array('milyar','juta','ribu','ratus','puluh','');
  29.     }
  30.  
  31.     function eja($n) {
  32.  
  33.     $i=0; $str='';
  34.     while($n!=0){
  35.  
  36.         $count = (int)($n/$this->angka[$i]);
  37.  
  38.         if($count>=10) $str .= $this->eja($count). " ".$this->satuan[$i]." ";
  39.         else if($count > 0 && $count < 10)
  40.             $str .= $this->dasar[$count] . " ".$this->satuan[$i]." ";
  41.  
  42.  
  43.             $n -= $this->angka[$i] * $count;
  44.             $i++;
  45.         }
  46.         $str = preg_replace("/satu puluh (\w+)/i","\\1 belas",$str);
  47.         $str = preg_replace("/satu (ribu|ratus|puluh|belas)/i","se\\1",$str);
  48.  
  49.  
  50.         return $str;
  51.     }
  52. }
  53.  
  54.  
  55. ?>
Add Comment
Please, Sign In to add comment