Tuesday, July 3, 2012

PHP Tips and Tricks

Remove leading zero '0030' => '30' :

$var = '0030';
$num =  (int)$var;

Execute external program : source

Exec($runCommand)->StdOut->ReadAll;
echo "

$output

"; ?>
Other script for executing external program link1 link2

Get basepath : source

 /dev/null &`;
  }
  else //windowz
  {
    $WshShell = new COM("WScript.Shell");
    $oExec = $WshShell->Run($runCommand, 7, false);
  }
?>

JQuery tips and tricks

Show or hide element with radio button

Scenario : when i click 'j3' (radio button), 'kodesuratkeluar' will show up.. when i select others it will hide
$('input[name="jenissurat_id"]').change(function() {
 if ($('#j3:checked').length) $('#kodesuratkeluar').show();
 else $('#kodesuratkeluar').hide();
});