PHP Tutorials – How to Include Comments in PHP


A comment is a line of code that is not supposed to be executed as part of the program. You can use a comment to show others what you are doing or to reminder yourself of what you did.

A common occurrence is where a programmer comes to look at the code they wrote on year or so down the line and they have to re-figure out what they were thinking when they wrote the code. A comment can remind you of what you were thinking.

In PHP there are a couple of ways through which you can include comments in your code.

Create an empty text file document and save it in your local computer using the name  comments.php  and include the code below.

One way to include comments in your code is to use a double forward slash as shown below.

The text that is on the same line as the double forward slash is not printed in the browser.

Another way to include comments in your code is to use the hash symbol in from of the comment string as show in the code below.

The line of text that is in front of the #  symbol is not printed in the browser.

In both the cases above we have only included the comments on a single line. In some instances you might want your comments to occupy multiple lines. In order to include comments in multiple lines we use the  /*...*/ combination as shown below.

The text between the  /*  and the  */  are not printed in the browser. You can let your comments span as many lines you like.

These are all the three methods you can use to include comments in your PHP code.

Found this article useful? Please share your thoughts below.

Liked this article? You might also like PHP Tutorials – Case Sensitivity in PHP

About the Author Geoffrey Barnes

Geoffrey is an experienced software developer and open source evangelist. When not coding he writes and talks about current technology trends, small business tips and developer productivity hacks. He is no coffee addict.

follow me on:

Leave a Comment: