You are on page 1of 14

How PHP works. To write a simple PHP page. To understand and work with simple PHP variables.

To use PHP operators. To pass values from one page to another via the URL.

When a user navigates in her browser to a page that ends with a .php extension, the request is sent to a web server, which directs the request to the PHP interpreter. As shown in the diagram above, the PHP interpreter processes the page, communicating with file systems, databases, and email servers as necessary, and then delivers a web page to the web server to return to the browser.

<?php PHP CODE GOES IN HERE ?> This is the most commonly used (and recommended) form. It is known as the XML style, because it can be used inside of an XML document without causing the document to become poorly formed

PHP statements must be inside of PHP tags to be processed by the PHP interpreter. Each PHP statement must end with a semicolon, which tells the PHP interpreter that the statement is complete. If a semi-colon does not appear at the end of a line, the interpreter will assume that the statement continues onto the next line.

PHP has two forms of comments: Single-line comments begin with a double slash (//). Multi-line comments begin with "/*" and end with "*/". Ex:
// This is a single-line comment /* This is a multi-line comment. */

<html> <head> <title>Hello World!</title> </head> <body> <?php //Write out Hello World! echo 'Hello World!'; ?> </body> </html>

Code between <?php and ?> is processed by the PHP interpreter. The echo command is used to print text back to the browser.

PHP variables begin with a dollar sign ($) as shown below. Ex:
$var_name = "Value";

Variables Type Integer

Double String Boolean Array Object

Explanation Whole Number

Real Number String of characters True or False List of item Instance of a class

consist of letters, digits, underscores and dollar signs cannot begin with a digit are case sensitive

<?php $Greeting = 'Hello World!'; ?> <html> <head> <title><?php echo $Greeting; ?></title> </head> <body> <?php echo $Greeting; ?> </body> </html>

Code Explanation This time the string "Hello World!" is stored in the $Greeting variable, which is output in the title and body of the page with an echo command.