PHP - Hypertext Preprocessor

An HTML embedded scripting language - PHP can be interspersed within HTML

PHP is a scripting language, as opposed to a programming language. PHP is designed to do something only after an event occurs - for example, when a user submits a form or goes to a URL.

PHP is a server-side, cross-platform technology. Server-side refers to the fact that everything PHP does occurs on the server (as opposed to on the client, which is the website's viewer's computer - javascript is client side). Its cross-platform nature means that PHP runs on most operating systems, including Windows, Unix, and Macintosh.

When a visitor goes to a Web site written in PHP, the server reads the PHP code and then processes it according to its scripted directions. This differs from a static HTML site where, when a request is made, the server merely sends the HTML data to the Web browser and there is no server-side interpretation occurring.

This means that PHP must be installed on your server. To check for php on a server create a php file that runs the following function:

<?php
  phpinfo();
?>

PHP Basic Syntax

Formal XML style
To place PHP within an HTML document surround the code with PHP tags using the formal XML style:

<?php
  //code goes here
?>

Anything placed within these tags will be treated by the Web server as PHP (meaning the PHP interpreter will process the code rather than it being immediately sent to the Web browser).

You can embed multiple sections of PHP code within a single HTML document (i.e. you can go in and out of the two languages)

Extensions used that web servers recognize: .html or .htm for standard HTML pages and .php is pereferred for php scripts. If you don't save the file using an appropriate PHP extension, the script will not execute.

Sending Data to the Web Browser

PHP has a number of built-in functions written specifically to accomplish this. Most common functions are:

echo();
print();
include();

all statements must end with a semicolon:

echo ('Hello, world!');
print ("It's nice to see you.");
include("path/filename.php");

either single quotations or double quotations may be used.

PHP is case sensitive.

PHP is white space insensitive, meaning that you can space out your code for greater legibility.

Writing Comments

PHP supports three comment types
  1. The pound or number symbol (for single line use only):
        # This is a comment.
  2. the second stems from C++ programming, using two forward slashes (for single line use only):
        // This is a comment
  3. Used with C and allows for comments to run over multiple lines:
        /* This is a multiple line comment
    that closes with the reverse symbols */

By surrounding any block of PHP code with C-style comments, you can render that code inert without deleting it from your script. By uncommenting the block later, you can reactivate it.

PHP is commonly used to:

PHP is open source: PHP.NET