Site icon TestingDocs.com

PHP Comments

Overview

We can use PHP Comments to explain the PHP code to others. Comments are ignored by the PHP Interpreter and the web browser.

Single Line Comment

Single line comment can be added in PHP code using the double forward slash //.

Syntax

<?php
// This is single line PHP comment
?>

Multi-line Comment

We can also use multi-line comments in PHP Code. To start a multi line comment, a forward slash and an asterisk (/*) is used. To end it an asterisk and a forward slash (*/) is used.

Syntax

<?php
/* This is a multi line comment in PHP example
This will be ignored by the PHP interpreter
and the web browser */
?>

Example


<!DOCTYPE html>
<!–
PHP Comment Demo
–>
<html>
<head>
<meta charset=”UTF-8″>
<title>PHP Comment Demo</title>
</head>
<body>
<h1> PHP Comment Demo </h1>
<?php
//Sample PHP Code single Line comment
echo “Hello, This page can run PHP code! \n”;
?>
<br>
<br>
<?php
/*
This is a multi-line PHP comment.
Both the single-line and multi-line comments
would be ignored by PHP preprocessor and
web browser.
*/
echo “\n Notice that none of the PHP comments will appear here..”;
?>
<h1>PHP Tutorials </h1>
<h3>www.TestingDocs.com</h3>
</body>
</html>


Sample Output

 

Code Editors generally highlight comments in different color to visually separate it from the code.

 

Notice that none of the comments are displayed by the browser.

 

PHP Tutorials

PHP Tutorials on this website:

https://www.testingdocs.com/php-tutorials/

More Information on PHP

https://www.php.net/

Exit mobile version