PHP Syntax


The PHP script is applied to the server, and the blank HTML effect is restored to the browser.


Basic PHP Syntax

PHP script can be installed anywhere in the document.

PHP text starts with <? Php and ends with ?>:


<?php
// PHP code goes here
?>

The default file extension for PHP files is ".php"

A PHP file usually contains HTML tags, as well as a specific PHP text code.

Below, we have an example of a simple PHP file, with a PHP text that uses the built-in PHP function "echo" to extract the text "Hello World!" web page:


Example
<!DOCTYPE html>
<html>
<body>

<h1>My first PHP page</h1>

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


</body>
</html>

Note: PHP statements end in semicolon (;).



PHP Case Sensitivity

In PHP, keywords (e.g. if, otherwise, in time, echo, etc.), classes, tasks, and user-defined tasks are less sensitive.

In the example below, all three echo statements below are equally valid and valid:


Example
<!DOCTYPE html>
<html>
<body>

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


</body>
</html>

Note: However; all the variables are very sensitive!



See the example below; only the first statement that will show the value of $color variable! This is because $color, $ COLOR, and $ coLOR are considered three different variants:


Example
<!DOCTYPE html>
<html>
<body>

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


</body>
</html>