Archive

Archive for the ‘PHP’ Category

PHP’s error reporting levels

April 30th, 2009 Comments off

The drudgery and pain of debugging and fine-tuning PHP can be alleviated when one takes full advantage of PHP’s various¬† error reporting levels that can be changed both in the config and on the fly at run time. To change the error reporting level on the fly during execution of a script, use PHP’s error_reporting() function (http://us.php.net/manual/en/function.error-reporting.php).¬† The error_reporting function takes a single int parameter which can be anyone of the following values

  • 1 (E_ERROR)
  • 2 (E_WARNING)
  • 4 (E_PARSE)
  • 8 (E_NOTICE)
  • 16 (E_CORE_ERROR)
  • 32 (E_CORE_WARNING)
  • 64 (E_COMPILE_ERROR)
  • 128 (E_COMPILE_WARNING)
  • 256 (E_USER_ERROR)
  • 512 (E_USER_WARNING)
  • 1024 (E_USER_NOTICE)
  • 2048 (E_STRICT)
  • 4096 (E_RECOVERABLE_ERROR)
  • 8192 (E_DEPRECATED)
  • 16384 (E_USER_DEPRECATED)
  • 30719 (E_ALL)

Let’s say you actually wanted to implement the E_STRICT level in a single PHP script. Adding the following code, most likely at the top of your script will handle this:

<?php
error_reporting(2048);
?>

Easily grabbing the hour from PHP

April 14th, 2009 Comments off

Ever need to grab a portion of the current timestamp from PHP? Know how to grab the hour of the current time the server in MySQL using the HOUR() function, but not quite sure how to grab the hour through PHP? Try this handy little function in PHP:

idate(format)

According to the PHP manual page on idate (http://us3.php.net/manual/en/function.idate.php), the idate() function will:

“Returns a number formatted according to the given format string”

To make things easy, the idate function accepts only one format parameter and returns a single integer. To quickly and easily retrieve the hour of the current timestamp, just pass in the H parameter to the function.

For example:

$iHour = idate(‘H’);

To get the full list of parameters you can pass to the idate function, to see how the idate() differs from date(), or to find out more specifics, visit the idate function reference page here:  http://us3.php.net/manual/en/function.idate.php

Categories: PHP Tags: , ,