PHP Syntax

PHP is a server side scripting language which is executed on the server, and the plain HTML result is sent back to the browser. 

Let's understand the basic syntax of php code example

A PHP script can be placed anywhere in the document and it starts with <?php and ends with ?>

<?php
// You can write PHP Code here
?>

Default file extension of PHP files is ".php". 

 

Note: PHP statements end with a semicolon (;).

Example

<!DOCTYPE html>
<html>
<body>

<h1>My first PHP page</h1>

<?php
echo "Hello World!";
?>

</body>
</html>

PHP Case Sensitivity

In PHP Language all  keywords (e.g. ifelsewhileecho, etc.), classes, functions, and user-defined functions are not case-sensitive.

the below example show all three echo statements below are equal and legal:

Example :

<!DOCTYPE html>
<html>
<body>

<?php
ECHO "Hello World!<br>";
echo "Hello World!<br>";
EcHo "Hello World!<br>";
?>

</body>
</html>
Note: However; all variable names are case-sensitive!

Check the below example; only the first statement will display the value of the $color variable! This is because $color$COLOR, and $coLOR are treated as three different variables: 

<!DOCTYPE html>
<html>
<body>

<?php
$color = "blue";
echo "My car is " . $color . "<br>";
echo "My house is " . $COLOR . "<br>";
echo "My dress is " . $coLOR . "<br>";
?>

</body>
</html>