PHP Syntax

PHP script start with the <?php tag and ends with ?> tag. Between the two tags, a PHP script is written. <?php the opening tag and the ?> closing tag tells the engine to treat the enclosed code block as PHP code, rather than simple HTML.

 // opening tag

echo "Hello, world!";
 // executable block

?> // closing tag
Read also: How to install xampp in windows 10

Embedding PHP within HTML

.php extension is used as the file name suffix.  Inside a PHP file you can write regular HTML code. But ensure that all php codes are enclosed between <?php and ?> tags.

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>A Simple PHP File</title>
    <h1><?php echo "Hello, world!"; ?></h1>

Hope you understand the above code.

PHP Comments

PHP support single-line and also multi-line comments. To write a single-line comment either start the line with either two slashes // or a hash symbol #. For example:


// This is a single line comment
# This is also a single line comment

echo "Hello, world!";


To write multi-line comments, start the comment with a slash followed by an asterisk /* and end the comment with an asterisk followed by a slash */, like this:

This is a multiple line comment section
that spans across more than
one line
echo "Hello, world!";

Case Sensitivity in PHP

PHP is case sensitive language means $number and $NUMBER are treated as two different variables.


$number = 10; //assign 10 to the $number variable

// Print The Value
echo $number; //OUTPUT: 10
echo $NUMBER; //OUTPUT: Undefined Varibale warning for $NUMBER


Hope you got it!