PHP Language Syntax

  • The script of a PHP Language normally starts with <?php and ends on ?> and its script usually placed anywhere in the document or file. Moreover, your files will save with the extension of .php on your desktop.
  • A PHP Language always contains some PHP scripting and HTML tags.
<?php
// You can write the code here
?>

The above tags symbolizes the PHP Language Syntax clearly and below we have explained some popular examples of PHP Language.

Example of PHP Language

The example given below explains the flow of the program. So, <h1> tag here describes the heading of your page. And echo will displays the text on your page.

<!DOCTYPE html>
<html>
<body>
<h1> The first page of my website </h1>
<?php
echo "Hello World!";
?>
</body>
</html>

Case-Sensitivity of PHP Language

  • PHP language is very case sensitive means if you use variable like $kite and $KITE then it treats both as a different variable.
  • But if you took the pre-defined functions, classes or keywords like (if, else, echo and while) then it is not case sensitive.
<!DOCTYPE html>
<html>
<body>

<?php
$type = "Corolla";
echo "The type of my office car is " . $type . "<br>";
echo "The type of my house car is " . $TYPE . "<br>";
?> 

</body>
</html>

Only first $type will give you the type of your car. Another example is given below which defines the insensitivity of functions, classes and keywords.

<!DOCTYPE html>
<html>
<body>

<?php
echo "The type of my office car is <br>";
ECHO "The type of my office car is <br>";
?> 

</body>
</html>

Now, both gives you the same answer which shows that this an insensitive case.

PHP Language Comments

Comment is actually the most important part in the code for the point of readability. Means a comment is used for the understanding of other person who is reading your program. Its also used for the convenience of programmer that they will always remember what they did when they approached it after some years. Below there is an example of how to comment in a code.

<!DOCTYPE html>
<html>
<body>

<?php

// This is a single-line comment

# This is also used for a single-line comment

/*
This is a multiple-lines comment block
that can be implement on multiple
lines
*/

?>

</body>
</html>