PHP Comments
PHP Comments
We can use PHP Comments to explain the PHP code to others. The PHP Interpreter and the web browser ignore comments. Comments in PHP can be single-line, starting with // or #, or multi-line, enclosed in /* */.
Single Line Comment
Single-line comments can be added in PHP code using the double forward slash //.
Syntax
<?php
// This is a 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 (/*) are used. To end it, an asterisk and a forward slash (*/) are 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 the browser does not display the comments.
Comments help clarify what the code is doing, making it easier for others to understand the purpose and functionality of the code.
Ease of Maintenance: With well-commented code, future developers can quickly grasp how the code works and make modifications or fixes more efficiently.
—
PHP Tutorials
PHP Tutorials on this website:
More Information on PHP