Syntax of PHP:

Here is a basic syntax for PHP which can be placed in a document anywhere using that.

PHP start with “<?php” this tag and ends with “?> this tag.

Save your php file with ”.php” extension. PHP file can contain some HTML tags and PHP code to execute.

Example:

Below is a simple example for printing a sentence using php code

Short –php-open-tags:

You can also use short tag which looks like as follows:

<?…………………..?>

That means you don’t have to write php after the opening tag but to use this pattern of tag you have to do two things first.

  • When you creating a php file you have to choose “enable-short-tags” in configuration option.
  • Than you have to set “short_open_tag” to “on” in php.ini file.

 Case Sensitivity in PHP:

PHP is a case sensitive language so always be sure when you are creating a PHP code. Here is a example which will explain you that how PHP is case sensitive:

Example:

In following example we created a variable which stores a value and than we print it. So the first time it will print the name but for the second time it will occur a Notice on browser that the variable “$NAME” is undefined.

NOTE:

There are some important things that you should know:

  • PHP is a white space insensitive language means it will not matter for PHP that how many white space character you used in a statement.
  • All PHP statements should be terminated by semicolon(;) .

One response to “Syntax of PHP”

  1. Louis Vuitton says:

    I’ve spent the last 10 minutes browsing a couple of posts here and decide to subscribe to your feed!

Leave a Reply

Your email address will not be published. Required fields are marked *