-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathctw2.php
200 lines (198 loc) · 5.76 KB
/
ctw2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<center>
<form method="post" target="_self">
<input type="text" name="val" id="val" <?php if($_POST) echo 'placeholder="'.$_POST["val"].'"';?>/>
<input type="submit" name="OK" id="OK" value="OK, proses bro.."/>
</form>
</br><hr>
<?php
if($_POST&&$_POST['val']!=''){
$cur = $_POST['val']; // iki input e bro..
rupiah($cur);
echo "<i><b>".ctw($cur,2)."</b></i>";
}
function rupiah($cur){ // bwt nampilin format rupiah
echo "Rp. ".number_format($cur, 0, ',', '.').",-</br>";
}
function ctw($cur,$f){
$l = strlen($cur);
$c = str_split($cur);
$w = '';
$counter = 1;
$no = 1;
$non = 1;
$nonj = 1;
$nonm = 1;
$nont = 1;
$nonb = 1;
for($i=0;$i<$l;$i++){
$dec = $l-$i;
if($c[$i]==1) $v = "satu ";
if($c[$i]==2) $v = "dua ";
if($c[$i]==3) $v = "tiga ";
if($c[$i]==4) $v = "empat ";
if($c[$i]==5) $v = "lima ";
if($c[$i]==6) $v = "enam ";
if($c[$i]==7) $v = "tujuh ";
if($c[$i]==8) $v = "delapan ";
if($c[$i]==9) $v = "sembilan ";
if($c[$i]==0) $v = "";
if($dec==17){ // puluhan bilyar
if($v=="satu "){
if($c[$i+1]==0) $w = $w."sepuluh ";
if($c[$i+1]==1) $w = $w."sebelas ";
if($c[$i+1]==2) $w = $w."dua belas ";
if($c[$i+1]==3) $w = $w."tiga belas ";
if($c[$i+1]==4) $w = $w."empat belas ";
if($c[$i+1]==5) $w = $w."lima belas ";
if($c[$i+1]==6) $w = $w."enam belas ";
if($c[$i+1]==7) $w = $w."tujuh belas ";
if($c[$i+1]==8) $w = $w."delapan belas ";
if($c[$i+1]==9) $w = $w."sembilan belas ";
$nonb = 0;
}
else if($v=="") $w = $w."";
else
$w = $w."".$v." puluh ";
}
if($dec==16){ // bilyar
if($nonb==1){
if($v==""&&$c[$i-1]==0&&$c[$i-2]==0) $w = $w."";
else $w = $w."".$v." bilyar ";
}
else $w = $w."bilyar ";
}
if($dec==14){ // puluhan trilyun
if($v=="satu "){
if($c[$i+1]==0) $w = $w."sepuluh ";
if($c[$i+1]==1) $w = $w."sebelas ";
if($c[$i+1]==2) $w = $w."dua belas ";
if($c[$i+1]==3) $w = $w."tiga belas ";
if($c[$i+1]==4) $w = $w."empat belas ";
if($c[$i+1]==5) $w = $w."lima belas ";
if($c[$i+1]==6) $w = $w."enam belas ";
if($c[$i+1]==7) $w = $w."tujuh belas ";
if($c[$i+1]==8) $w = $w."delapan belas ";
if($c[$i+1]==9) $w = $w."sembilan belas ";
$nont = 0;
}
else if($v=="") $w = $w."";
else
$w = $w."".$v." puluh ";
}
if($dec==13){ // trilyun
if($nont==1){
if($v==""&&$c[$i-1]==0&&$c[$i-2]==0) $w = $w."";
else $w = $w."".$v." trilyun ";
}
else $w = $w."trilyun ";
}
if($dec==11){ // puluhan milyar
if($v=="satu "){
if($c[$i+1]==0) $w = $w."sepuluh ";
if($c[$i+1]==1) $w = $w."sebelas ";
if($c[$i+1]==2) $w = $w."dua belas ";
if($c[$i+1]==3) $w = $w."tiga belas ";
if($c[$i+1]==4) $w = $w."empat belas ";
if($c[$i+1]==5) $w = $w."lima belas ";
if($c[$i+1]==6) $w = $w."enam belas ";
if($c[$i+1]==7) $w = $w."tujuh belas ";
if($c[$i+1]==8) $w = $w."delapan belas ";
if($c[$i+1]==9) $w = $w."sembilan belas ";
$nonm = 0;
}
else if($v=="") $w = $w."";
else
$w = $w."".$v." puluh ";
}
if($dec==10){ // milyar
if($nonm==1){
if($v==""&&$c[$i-1]==0&&$c[$i-2]==0) $w = $w."";
else $w = $w."".$v." milyar ";
}
else $w = $w."milyar ";
}
if($dec==8){ // puluhan juta
if($v=="satu "){
if($c[$i+1]==0) $w = $w."sepuluh ";
if($c[$i+1]==1) $w = $w."sebelas ";
if($c[$i+1]==2) $w = $w."dua belas ";
if($c[$i+1]==3) $w = $w."tiga belas ";
if($c[$i+1]==4) $w = $w."empat belas ";
if($c[$i+1]==5) $w = $w."lima belas ";
if($c[$i+1]==6) $w = $w."enam belas ";
if($c[$i+1]==7) $w = $w."tujuh belas ";
if($c[$i+1]==8) $w = $w."delapan belas ";
if($c[$i+1]==9) $w = $w."sembilan belas ";
$nonj = 0;
}
else if($v=="") $w = $w."";
else
$w = $w."".$v." puluh ";
}
if($dec==7){ // jutaan
if($nonj==1){
if($v==""&&$c[$i-1]==0&&$c[$i-2]==0) $w = $w."";
else $w = $w."".$v." juta ";
}
else $w = $w."juta ";
}
if($dec==5){ // puluhan ribu
if($v=="satu "){
if($c[$i+1]==0) $w = $w."sepuluh ";
if($c[$i+1]==1) $w = $w."sebelas ";
if($c[$i+1]==2) $w = $w."dua belas ";
if($c[$i+1]==3) $w = $w."tiga belas ";
if($c[$i+1]==4) $w = $w."empat belas ";
if($c[$i+1]==5) $w = $w."lima belas ";
if($c[$i+1]==6) $w = $w."enam belas ";
if($c[$i+1]==7) $w = $w."tujuh belas ";
if($c[$i+1]==8) $w = $w."delapan belas ";
if($c[$i+1]==9) $w = $w."sembilan belas ";
$non = 0;
}
else if($v=="") $w = $w."";
else
$w = $w."".$v." puluh ";
}
if($dec==4){ // ribuan
if($non==1){
if($v=="satu "&&$l==4) $w = $w."seribu ";
else if($v==""&&$c[$i-1]==0&&$c[$i-2]==0) $w = $w."";
else $w = $w."".$v." ribu ";
}
else $w = $w."ribu ";
}
// ratusan, ratusan ribu, ratusan juta, ratusan milyar, ratusan trilyun, ratusan bilyar >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
if($dec==3||$dec==6||$dec==9||$dec==12||$dec==15||$dec==18){
if($v=="satu ") $w = $w."seratus ";
else if($v=="") $w = $w."";
else $w = $w."".$v." ratus ";
}
if($dec==2){ // puluhan
if($v=="satu "){
if($c[$i+1]==0) $w = $w."sepuluh ";
if($c[$i+1]==1) $w = $w."sebelas ";
if($c[$i+1]==2) $w = $w."dua belas ";
if($c[$i+1]==3) $w = $w."tiga belas ";
if($c[$i+1]==4) $w = $w."empat belas ";
if($c[$i+1]==5) $w = $w."lima belas ";
if($c[$i+1]==6) $w = $w."enam belas ";
if($c[$i+1]==7) $w = $w."tujuh belas ";
if($c[$i+1]==8) $w = $w."delapan belas ";
if($c[$i+1]==9) $w = $w."sembilan belas ";
$no = 0;
}
else if($v=="") $w = $w."";
else $w = $w."".$v." puluh ";
}
if($dec==1){ // satuan
if($no==0) $w = $w."";
else $w = $w."".$v;
}
}
$w = $w." rupiah";
if($f==0) return $w;
else if($f==1) return ucfirst($w);
else if($f==2) return ucwords($w);
}
?>