PHP Syntax

A PHP script starts with the <?php and ends with the ?> tag.

PHP delimiter <?php and ?> in the following example simply tells the PHP engine to treat the enclosed code block rather than simple HTML.

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

All PHP statement end with a ; this tells the PHP engine that the end of the current statement has been reached.

> Embedding PHP within HTML

PHP files are plain text files with .php extension. PHP file you can write HTML like you do in regular HTML pages as well as embed PHP codes for server side execution.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Hello world!</title>
</head>
<body>
    <h1><?php echo "Hello world!"; ?></h1>
</body>
</html>

PHP Comments

Comment in PHP code is a line that is not executed as a part of the program and It's only purpose is to read by someone who is looking at the code.

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

<?php
// This is a single line comment
# This is also a single line comment
echo "Hello world!";
?>

Syntax for multiple-line comments:

<!DOCTYPE html>
<html>
<body>

<?php
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
?>

</body>
</html>