PHP Standard Syntax

A PHP code block must be written inside the PHP opening and closing tags () called Canonical PHP tags. The start tag tells the PHP parser to begin parsing, and the closing tag tells to end the parsing. The PHP can be embedded within the HTML code, and anything outside the PHP opening and closing tags will be treated as HTML code. The PHP code can be embedded with HTML code, and the file must be saved with a PHP extension.

The PHP code is run on the server-side, and the output that is displayed on the browser is the HTML outcome. When we write the PHP code in a file, we have to save the file on which we have written PHP code with the .php extension.

Before writing the code in PHP, we need to understand a few things:-

1) How a PHP script starts:- PHP script always starts with .

			

<?php
# some important PHP code that we have written
?>

				

2) How to add comments in PHP code:- You can add comments in a PHP script in two ways-

  1. By using #
  2. By using //
			

<?php
// We are writing a comment 
# We are again writing a comment in a second way
?>

				

We have learned how to write comments ( single-line comments). Let us now see how we can write multiple-line comments or say multiline comments.

			

<?php
/* There are 8 planets in our solar system. Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune.
This is some information about the solar system */
?>

				

PHP case sensitivity:-

1) PHP is not case-sensitive to keywords:- In PHP, we have keywords like echo, if, else, while, etc., and some functions and user-defined functions that are not case-sensitive.

			

<?php
echo "There are eight planets in our solar system<br>";
EcHo "There are eight planets in our solar system that we know.";
?>

				

Output:

There are eight planets in our solar system There are eight planets in our solar system that we know.

Both echo and EcHo displayed the output because keywords are non-case sensitive in PHP.

2) PHP is case-sensitive to variable names:- In PHP, when we name variables, we have to remember that variable names are case-sensitive in PHP. Let us understand this with the help of an example:-

			

<?php
$Movie = "The Batman";
echo "My Favourite movie is " . $Movie . "<br>";
echo "My Favourite movie is " . $MOVIE . "<br>";
echo "My Favourite movie is " . $movie . "<br>";
?> 

				

Output:

My Favourite movie is The Batman My Favourite movie is My Favourite movie is

In the above example, we can see that only the variable $Movie gives us our output, not the others($MOVIE, $movie). This example shows us that variable names are case-sensitive in PHP.