The PHP “heredoc” Syntax

An excellent alternative method to assigning string variables is to use the heredoc syntax. If you are assigning long strings of text with characters that need escaping, try this: To me, it looks a bit messy at first, but it does make large chunks of text more readable in your code. Consider this alternative to…

Storing Simple Values and Parameters – define() your PHP constants

In most applications there is a need for set values that do not change during the execution of a script. Examples of these values are: Database Settings (username, password etc.) Database Table Names Directory Paths Website URLs A bad way to handle these values is to “hard code” them. This is the process of inserting…

PHP REGISTER_GLOBALS turned off? Hack It Back

REGISTER_GLOBALS is a PHP directive that, when enabled, automatically initialises variables with the values from forms, sessions, GET etc. For example, the data in a login form with the input fields named “username” and “password” will automatically be available as $username and $password. REGISTER_GLOBALS is, in my opinion, very bad practice and should be avoided…

Debugging an Array – Print it Recursively with print_r()

Nice and simple one.. If you want to see whats in an entire array, use the print_r function. This will give you a nicely formatted output of the array showing all dimensions. Try it: {code type=php}$anArray = array(0=>’cheese’,1=>’bacon’,2=>’apples’); print_r($anArray); {/code} Tip if you are viewing this via the output of a webpage, view the source…