PHP structure and syntax


The web page that is created in PHP having an extension of .php
The PHP script that you want to execute at server side must contained between <?php and ?>.
<?php
// code to be execute on server side
?>

You can combine your PHP script with HTML code to design a web page that supports dynamic script execution facility at server side.
Whenever you are requesting any web page with .php extension the server locates the requested file and execute the script that is specified between <?php and ?> tag and returns output in the form of just HTML back to the user.

How to create PHP pages?


You can create a PHP page in various text editor programs such as Notepad, WordPad, and Notepad++ etc…
Open any of the text editor program and start writing your PHP script.
After you finish writing of PHP script you need to save it with .php extension at particular location depending upon the type of the server you are using to compile and execute your script.
Once you save the PHP page with .php extension you can execute the page.

     

Rules of PHP syntax


In order to successfully execute the PHP script you must follow the PHP syntax rules.
Following are some important rules for writing PHP script.
(1) The script of PHP must contain between <? php ?>

For Example:
<?php
echo “Hello Welcome to PHP”;
?>

(2) Every statement inside <? php ?> must ends with a semicolon.

For Example:
<?php
echo “Hello Welcome to PHP”; // Valid
echo “First Script” // Not Valid
?>

(3) String Must contained between either single quotation mark or double quotation mark.

For Example:
<?php
echo “Hello Welcome to PHP”; // Valid
echo ‘First Script’; // Valid
echo First Script; // Not Valid
?>

(4) You can make a line as a comment using either // or /* */. No other symbols are permitted for making a line as a comment.

For Example:
<?php
// This my First PHP Script
echo “Hello Welcome to PHP”; // Valid
echo ‘First Script’; // Valid
?>

(5) Every variables in a script must starts with $ sign.

For Example:
<?php
// This my First PHP Script
$Number1 = 10; //valid
Number1 = 10; // Not Valid
?>

(6) Name of the variable can not start with digit and it can not contain white spaces.

For Example:
<?php
// This my First PHP Script
$Number1 = 10; //valid
$1Number = 10; // Not Valid
$Number 1 = 10; // Not Valid
?>

(7) PHP is case sensitive.

Download Projects


Download Programs