PHP Comments

PHP comments are simply text that is ignored by the PHP engine. The purpose of comments is to let you add message to yourself (and other programmers) that explain what your code does. It’s  always a good idea to add comments to your code, even if you are the only programmer working on it. Sometimes code that makes sense you write it can seem as clear as mud in three months time, so comment can really help.

PHP supports single –line comments and multi-line both. To write a single line comment, start the with either two slashes (//) or a hash symbol (#) .

PHP comments Example-

// This code displays the current date

#  This code displays the current date

To write multi-line comments, start the comment with a slash followed by an asterisk (/*) and end the comment with an asterisk followed by a slash (*/), as follows:


This code displays the

current time in a nice,

easy-to-read format.


So you might comment the PHP code in the hello_with_date.php script like this.


// Get the current date in the readable format

$ current Date = date(“g:i:s  a”);

// Display greeting and Date to the visitor

Echo “Hello, Word! The current time is $currentDate”;


Lear more : Comments in C++

Leave a Reply

Your email address will not be published.