Mixing PHP/HTML and Commenting in PHP

PHP

The primary use of PHP is to build websites and web applications. Since browsers use HTML and JavaScript to render websites, the output generated by PHP is in HTML. The HTML codes that you see in websites like Facebook are the output after PHP processed it.

PHP code is mixed with HTML tags to produce the desired output. You save such files with a .php extension. You can even save files with just html with a .php extension and they still work.

You can also mix HTML within the PHP code in the following way:

<?php
echo "Hello World<br />Goodnight World";
?>
Output:
Hello World
Goodnight World

Notes:

  1. Every line of PHP code ends in ; (semi-colon).
  2. Line breaks do not matter as long as you get the syntax right.

Commenting in PHP

If you want to insert notes and comments in PHP to make the code easily understandable here’s how you do it:

Single line comments begins with // or #. Double slashes are more common.

Example:

<?php
//This is a comment
//This is another comment
#More Comments
?>

Multiple line comments: Begins with /* and ends with */

Example:

<?php
/* This is a comment
This is another comment
*/
?>
Note: Nothing is returned in the browser from these comments.