PHP Programming/Code Snippets

Code snippets are useful for any beginners to learn code from.

Basic Level
Bobby $var
 * - This language construct will echo the text between the quotes. This is not a function but a language construct.
 * - Notice the double quotation marks. Because double quotation marks are used, this will print the value of the variable. If $var="Bobby", this will output:
 * - Notice that the quotation marks are now single. This will output the literal keystrokes inside the quotes. The example will output:
 * - Other than substituting the value of a variable for the variable name (and one or two other minor items), double quotes will quote literal keystrokes. So this will output:

Joshua fit the battle of Jericho.

Again, if single quotes were used —  — this would output:

Joshua fit the battle of $var. 1214
 * - If you only want to print the value of a variable, you don't need quotes at all. If the value of $var is "1214", the code will output:
 * - This language construct will include the page between the quotes. Can NOT be used with dynamic pages, e.g.  would not work. This is not a function but a language construct.
 * - Function that returns a date from a Unix Timestamp - where H is the hour, i is the minutes, s is the seconds, d is the day, m is the month and Y is the year in four digits - e.g.  would return   on 10th August 2006 at 12:22:01.
 * - Function that deletes the file specified in filename.

OOP
Include OOP based examples, made by experienced developer

Basic Level
Basics, working only on PHP 5.

E.g.  will write Text to save to filename, but will overwrite existing text whereas   will write Text to save to filename, but will not overwrite existing text (instead it appends).
 * - Functions that saves the text specified in Text to save to the file specified in filename. Will overwrite existing file contents unless another parameter FILE_APPEND is added.

OOP

 * 1) Input validation by Kgrsajid.
 * 2) Advanced Input validation by nemesiskoen.