PHP

PHP Programming

PHP Programming

Php programs are written using a text editor, such a notepad, and simple text just like html pages. One of the benefits of using php is that the language is relatively simple and straightforward. As with any computer language, there is usually more than one way to perform the same task.

You can research different ways to make your code more efficient once you feel comfortable writing php programs. But for the sake of simplicity we cover only the most common uses, rules and functions of php.

First, you should always keep these two basic rules of php in your mind:

1. Php code is denoted in the page with opening and closing tags, as follows:

<?php ——> Opening tag

?> ———> Closing tag

2. Generally speaking, php statements end with a semicolon ;

<?php

$var = 1+1;

echo $var;

?>

You can add comments in your program by using double forward slashes (//) for one-line comments or /* to mark the start and */ to mark the end of a comments that may extend over several lines.

Example:

<?php

// check to make sure the first name is equal to Matt before granting access

If ($_POST[‘fname’] = = ‘Matt’)

{

echo Hello . $_POST[‘fname’] ;

}

else

{

echo ‘Your name isn’t Matt so you cannot enter the website.’;

}

?>

However, unlike HTML the php files end with .php extension. This extension signifies to the sever that it needs to parse the php code before sending the resulting html code to the viewer’s web browser.