1. Single quotes, double quotes # $howdy = ‘everyone’; # $foo = ‘hello $howdy’; # $bar = “hello $howdy”; $foo outputs to “hello $howdy” and $bar gives us “hello everyone”. That’s one less step that PHP has to process. It’s a small change that can make significant gains in the performance of the code. 2. [...]
Archive for the ‘PHP’ Category
10 PHP Mistakes
February 27, 2009PHP Benchmark
February 27, 20091. For-loop test Cth. “for ($i=0; $i<$size; $i++)” dibandingkan “for ($i=0; $i<sizeOf($x); $i++)” loop 1000 x, With pre calc – count() Total time: 117 µs Without pre calc – count() Total time: 49465 µs With pre calc – sizeof() Total time: 117 µs Without pre calc – sizeof() Total time: 48491 µs 2. Menggunakan [...]
Contoh script membaca file import (txt file)
February 20, 2009<? /* File ini akan mengambil text files dan menampilkannya di layar */ if ($_POST[Submit]==”Import”) { $fd = fopen($_FILES["userfile"]["tmp_name"],”r”); while (!feof($fd)) { $buffer = fgets($fd, 4096); $tmp_data = split(“\t”, $buffer); for ($i=0; $i<count($tmp_data); $i++) { echo $tmp_data[$i].” – “; } echo “<br>”; } } ?> <form enctype=”multipart/form-data” method=”post”> <table> <tr> <td>Nama File </td> <td><input [...]
Membuat Register Global Off Dari Script
December 24, 2008<? if (!ini_get(‘register_globals’)) { $superglobals = array($_SERVER, $_ENV, $_FILES, $_COOKIE, $_POST, $_GET); if (isset($_SESSION)) { array_unshift($superglobals, $_SESSION); } foreach ($superglobals as $superglobal) { extract($superglobal, EXTR_SKIP); } ini_set(‘register_globals’, true); } ?>
Create an Upload-File Form
December 24, 2008To allow users to upload files from a form can be very useful. Look at the following HTML form for uploading files: <html> <body> <form action=”upload_file.php” method=”post” enctype=”multipart/form-data”> <label for=”file”>Filename:</label> <input type=”file” name=”file” id=”file” /> <br /> <input type=”submit” name=”submit” value=”Submit” /> </form> </body> </html> Notice the following about the HTML form above: The enctype [...]