Screen Printing

TUTORIALS » PHP / MySQL » PHP essentials (guided tutorials)

Comments in PHP

When you write a PHP script, you can include text comments that will be ignored by the PHP parser.

Here are a few good reasons to include comments in your PHP scripts:
  1. As bookmarks inside large scripts.
  2. As a reminder of why you wrote a certain section the way you did it.
  3. As explanations and indications for fellow programmers/collaborators.
  4. As copyright notices, if other people will have access to your code.
  5. You can write a good joke. Who knows, maybe someday someone else is going to read it and have a good time.

Single line comments

To write a single-lined comment, just start it with two forward slashes.

 // This is a comment, it will be ignored by the PHP parser
 echo 'Hello world';
 // I would love to change the world, but they won't give me the source code

Multiple line comments

You can also write multi-line comments by enclosing them between /* and */.

 /* This is a multi-line comment.
 It will be ignored by the PHP parser.
 Regards to you all! */
 echo 'Hello world';

Remember, the PHP parser ignores the comments; thus they are not sent to the client's browser.

Now follow through our next tutorial – Variables in PHP.

Comments & Questions