Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function terbilang($angka1)
- {
- $temp="";
- //echo "terbilang". $angka."=".strlen($angka);
- $name = array("satu","dua","tiga","empat","lima","enam","tujuh","delapan","sembilan");
- for($i=0;$i<strlen($angka1);$i++) {
- $angka[$i]=substr($angka1, $i,1);
- //print substr($angka1, $i,1);
- }
- for($i=0;$i<strlen($angka1);$i++) {
- //echo $angka[$i];
- if((ord($angka[$i])>=48)and(ord($angka[$i])<=57)) {
- $temp.=$angka[$i];
- //echo $angka[$i];
- }
- //echo $angka[$i];
- }
- $text="";
- $angka=$temp;
- //echo "terbilang". $angka;
- if(strlen($angka)==0) {
- return false;
- }
- for($i=strlen($angka)-1;$i>=0;$i--) {
- $j=strlen($angka)-$i;
- $block[ceil($j/3)-1]=$angka[$i].$block[ceil($j/3)-1];
- }
- $block=array_reverse($block);
- for($i=0;$i<count($block);$i++) {
- $b = $block[$i];
- for($j=0;$j<strlen($b);$j++) {
- $pos = strlen($b)-$j;
- if(strlen($angka)==4) {
- if($i==0) {
- if($name[$b[$j]-1]=="satu") {
- $text="se";
- }
- }
- } else if(($name[$b[$j]-1]=="satu")and($pos<>1)) {
- $text.="se";
- } else {
- if(($pos==1)and($b[$j]<>"0")and(substr($text,-8)=="sepuluh ")) {
- $text=substr($text,0,strlen($text)-8);
- if($name[$b[$j]-1]=="satu") {
- $text.="se";
- } else {
- $text.=$name[$b[$j]-1]." ";
- }
- $text.="belas ";
- } else {
- $text.=$name[$b[$j]-1]." ";
- }
- }
- if($b[$j]<>0) {
- if($pos==3) {
- $text.="ratus ";
- } else if($pos==2) {
- $text.="puluh ";
- }
- }
- }
- switch(count($block)-$i) {
- case 2 : $text.="ribu ";break 1;
- case 3 : $text.="juta ";break 1;
- case 4 : $text.="milyar ";break 1;
- case 5 : $text.="trilyun ";break 1;
- }
- }
- return $text;
- //print $text;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement