Sabtu, Juli 23, 2011

PHP : Fungsi Terbilang

function kekata($x) {
 $x = abs($x);
 $angka = array("", "satu", "dua", "tiga", "empat", "lima",
 "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas");
 $temp = "";
 if ($x <12) {
  $temp = " ". $angka[$x];
 } else if ($x <20) {
  $temp = kekata($x - 10). " belas";
 } else if ($x <100) {
  $temp = kekata($x/10)." puluh". kekata($x % 10);
 } else if ($x <200) {
  $temp = " seratus" . kekata($x - 100);
 } else if ($x <1000) {
  $temp = kekata($x/100) . " ratus" . kekata($x % 100);
 } else if ($x <2000) {
  $temp = " seribu" . kekata($x - 1000);
 } else if ($x <1000000) {
  $temp = kekata($x/1000) . " ribu" . kekata($x % 1000);
 } else if ($x <1000000000) {
  $temp = kekata($x/1000000) . " juta" . kekata($x % 1000000);
 } else if ($x <1000000000000) {
  $temp = kekata($x/1000000000) . " milyar" . kekata(fmod($x,1000000000));
 } else if ($x <1000000000000000) {
  $temp = kekata($x/1000000000000) . " trilyun" . kekata(fmod($x,1000000000000));
 }
  return $temp;
}
function terbilang($x, $style=4) {
 if($x<0) {
  $hasil = "minus ". trim(kekata($x));
 } else {
  $hasil = trim(kekata($x));
 }
 switch ($style) {
  case 1:
   $hasil = strtoupper($hasil);
   break;
  case 2:
   $hasil = strtolower($hasil);
   break;
  case 3:
   $hasil = ucwords($hasil);
   break;
  default:
   $hasil = ucfirst($hasil);
   break;
 }
 return $hasil;
}

Source : http://maseko.com/code-snippet/php/fungsi-terbilang/

Jumat, Juli 22, 2011

Kamis, Juli 14, 2011

JQuery : Autocomplete Force Input

case : you use jquery autocomplete to replace an old style drop down menu and you want to force user to choose at least one of these input option.
solution : use a "mustMatch";

        $().ready(function() {
            $("#kategori").autocomplete("../actions/autocomplete.php?p=kategori", {
                width: 190,
                max: 2000,
                selectFirst: false,
                mustMatch:true,
            });
        });