PHP notes
mtbink.com logo

PHP notes

  1. To prevent the "Maximum execution time exceeded" error:
    set_time_limit(0);
    .
  2. Calculate time-lapse:
    $start = new DateTime();
    
    // do something...
    
    $end   = new DateTime();
    $lapse = $start->diff($end);
    
    /*
    Key Formatting Placeholders:
      %y: Years
      %m: Months
      %d: Days
      %h: Hours
      %i: Minutes
      %s: Seconds
      %a: Total number of days
    */
    echo "<p>LAPSE: " . $lapse->format("%s seconds") . "</p>";
    .
  3. Set timezone:
    date_default_timezone_set("Asia/Kuala_Lumpur");
    .
  4. Format date:
    date("d F Y (l) h:i:s A");
    // example: 25 April 2026 (Saturday) 07:44:15 PM 
    .
  5. Check class existence:
    if (class_exists("ZipArchive")) {
      echo "ZipArchive is enabled.";
    }
    .
  6. Unzip ZIP file:
    // ENTER SETUP
    // ===========
    $zipFile = "FILENAME.zip";
    // LEAVE SETUP
    // ===========
    
    $extractTo = "./";
    
    $zip = new ZipArchive;
    
    if ($zip->open($zipFile) === TRUE) {
      $zip->extractTo($extractTo);
      $zip->close();
      echo "<p class=\"success\">UNZIPPED.</p>";
    } else {
      echo "<p class=\"error\">ERROR: CANNOT UNZIP.</p>";
    }
    .
  7. Delete ZIP file:
    // ENTER SETUP
    // ===========
    $zipFile = "FILENAME.zip";
    // LEAVE SETUP
    // ===========
    
    if (file_exists($zipFile)) {
      if (unlink($zipFile)) {
        echo "<p class=\"success\">ZIP FILE DELETED.</p>";
      } else {
        echo "<p class=\"error\">ERROR: CANNOT DELETE ZIP FILE.</p>";
      }
    } else {
      echo "<p class=\"error\">ERROR: ZIP FILE NOT FOUND.</p>";
    }
    .
  8. Get max_execution_time:
    ini_get("max_execution_time");
    .
  9. PHP info:
    phpinfo();
    .

Search the entire website:

Flag Counter
RSS