# Syntax and Comments

Updated on Jan 12, 2022 by [Alan Morel](/content/alanmorel/index.html)

## Table of Contents

1. [Syntax](/content/classes/php/syntax-comments#syntax/index.html)
2. [Comments](/content/classes/php/syntax-comments#comments/index.html)

## Syntax

As you saw in our previous lesson where we did a simple `Hello World`, like so:

```php
<!DOCTYPE html>
<html>
    <head>
        <title>Diving into PHP</title>
    </head>
    <body>
        <?php
            // Display the text 'Hello World'
            echo('Hello World');
        ?>
    </body>
</html>
```

Hello World in PHP

The core syntax of [PHP](/content/classes/php/index.html) is actually quite simple. To declare PHP code, simply begin the code with `<?php` and end it with `?>`. Whatever is inside that will be interpreted as PHP code by the web server and executed.

In our example, the actual code being executed is a call to the PHP `echo` function. What this function does is simply take whatever it is given and echo it on the page. That is why you saw `Hello World` on the page even though the text wasn't included in a raw [HTML](/content/classes/html/index.html) form. Because PHP can and is commonly embedded within HTML pages, the final output will appear no different to the user than if the HTML had that text written directly, or hardcoded.

## Comments

If you noticed above the call to `echo`, there was this:

```php
<?php
    // Display the text 'Hello World'
?>
```

That is a **comment** in PHP. A comment is text that will be completely ignored by the web server as if it were never placed there in the first place. Comments are useful for leaving notes both to yourself and others about the surrounding code.

A comment spanning a single line is done with two slashes `//` or the hash symbol `#`, like so:

```php
<?php
    // I am a single-line comment
    # I am also a single-line comment
?>
```

But you can also write a comment that spans multiple lines by creating a block comment, like so:

```php
<?php
    /*
        I
        am
        a
        block
        comment
    */
?>
```

Great, that covers basic PHP syntax and how to leave comments!
