PHP Comments

Basically PHP supports 'C', 'C++' and Unix shell-style (Perl style) comments. PHP has two types of comment. The first type is the single line comment. The single line comment tells the interpreter to ignore everything that occurs on that line to the right of the comment.

Single line comment

To do a single line comment type "//" or "#" and all text to the right will be ignored by PHP interpreter.

Comments in PHP can be used for several purposes, a very interesting one being that you can generate API documentation directly from them by using PHPDocumentor (https://www.phpdoc.org/)

PHP Single Line Comment Example

<html>
<head>
<title>PHP Single Line Comments</title>
</head>
<body>
<?php   
echo "<h1>PHP Comments</h1>";
echo "Hello World!"; // This will print out Hello World!
echo "<br />This is my PHP commnet!"; // echo "I am commnted!";
// echo "I am commneted here!";
# echo "I don't do anything here";
?>
</body>
</html>

This will produce following result

PHP Comments
Hello World! 
<br>This is my PHP commnet!</br>

Notice that all of our echo statements were not evaluated because we commented them out with the single line comment. This type of line commenting is often used for quick notes about complex and confusing code or to temporarily remove a line of PHP code.

PHP Multi Line Comment

The multi-line PHP comment is similar to 'C', can be used to comment out large blocks of code or writing multiple line comments. This is begins with " /* " and ends with " */ ".

PHP Multi Line Comments Example

<html>
<head>
<title>PHP Multi Line Comments</title>
</head>
<body>
<?php   
/* The below code will read the file text and write into
the another text file currently file name is hardcoded for 
testing this code. */
echo "Hello World!"; 
/* echo "Multi-line comment!";
echo "This line will not run!";
*/
?>
</body>
</html>

This will produce following result

Hello World! 

Notice that all of the text statements inside "/*" and "*/" were not evaluated because we commented them out with the multi-line comment. This type of line commenting is often used for detailed explanation of something that should require.