PHP – Basic Syntax

The first and most important part is the syntex of PHP language which tells the server to execute the script/code as a PHP script. There are two types of Tags which are commonly used for PHP parsing.

Opening and Closing PHP Tags

The most commonly used Opening and Closing PHP Tags style is


The Basic Example using Opening and Closing PHP Tags

Short Open PHP Tags

These Tags are discouraged because it is only available if enabled using the short_open_tag php.ini configuration file directive

The most commonly used Short Open PHP Tags style is


The Basic Example using Short Open PHP Tags

Comment the PHP Code

The comments in PHP code are used used so that others can understand what the PHP function or script is doing. All the comment lines are not read/executed as part of the program. Its only purpose is to be read by others who is looking at the code.

Comments can be one-line or multi-line

Single-line PHP comments

Single-line PHP comments generally used for short explanations about the  relevant code. Here is the basic examples of single line comments.

Multi-lines PHP comments

Multi-lines comments are generally used to for more detailed explanations about the code or program. Here are the basic example of multi lines comments.

PHP is case sensitive language

PHP is a case sensitive language. It treats small and capital letters as a two different variables. The basic example to display case sensitive variables is given below:

The output of the above example will be :

Use of semicolon (;) in PHP

Semicolon has an important role in PHP. Each and every statement is followed by a semicolon (;). You can check the following example with (;) at the end of the statement.




Leave a Reply

Your email address will not be published.