The PHP syntax is a set of rules that define how to write a PHP program properly. PHP has no different from any other language. The PHP interpreter checks every line and returns an error if you do not follow the syntax properly.
We can use four different pairs of opening and closing tags in PHP.
- Default syntax
- Short open Tags
- Omit the PHP closing tag at the end of the file
PHP Default Syntax
Default syntax of PHP starts with “<?php” and ends with “?>“.
<?php //Your Code here ?>
By default the extension of PHP is .php
The PHP short tags start with “<?” and ends with “?>”
<? echo "This is PHP short tags example"; ?>
Omit tag at the end of the file
It’s better to omit the tag at end of the file if you using only PHP code on your webpage. Omitting PHP tag at end of the file will reduce the errors of whitespaces.
<?php echo "This is PHP omit tag example"; ?>
PHP Case sensitivity
In PHP the user-defined functions, classes are case-insensitive. Check out the below example for better understanding.
Example for case sensitivity :
<?php echo("First PHP case sensitivity <br />"); ECHO("Second We are learning PHP case sensitivity <br />"); EcHo("Third PHP case sensitivity <br />"); ?>
First PHP case sensitivity
Second We are learning PHP case sensitivity
Third PHP case sensitivity
Separating the PHP statements
Like many languages, PHP statements also terminated with a semicolon(;). If you are in the last line of your PHP code no need to add a semicolon(;).
- a semicolon
- a closing PHP tag