PHP Syntax

Register here to save your progress

? ? ?

To tell to the server that our scripts from a file represents PHP we need to include them between <?php and ?>.

<?php


?>

A PHP file must also have the extension .php at the ending of it's name, like "contact_us.php".

What are the delimiters for the PHP scripts?

Comments

When writing PHP code we may want to add some explanation lines or just add some short descriptions. This is a thing that it's quite encouraged, this way you or somebody else will understand better and easier the purpose of your code.

The server will not use the comments, it will treat them as they don't exist among the code.

To add a single line of comment use // at the beginning of the line.

<?php

//This is a single line of comment

How must a single line of comment start in PHP?

If you need to add longer comments you can use the delimeters /*, that marks the start, and */ that marks the end of the comment.

<?php

/* This is the first line
here is the second line

and here is the last line
*/

How do you add comments in PHP?