Comments in PHP are text contents which are ignored by the interpreter.
Comments are usually added with the purpose of making the source code easier
to understand for someone who is reading it. PHP supports C,C++,Java,Perl and Unix style comments.
In PHP we have 3 kinds of Comments,
1. Single line Comments. (
//)
2. Multi-line Comments. (
/* */)
3. Single line Shell/Perl like comments. (
#)
1. Single line Comments. (//)
Single-line comments starts with // and cannot span across multiple lines.
<html>
<head>
<body>
<h1>
<?php
echo "Hello there!"; //This is an example of Single line comment.
?>
</h1>
</body>
</html>
Output
Hello there!
2. Multiline Comments. (/* */)
Multi-line comments starts with /* and ends with */ and can span across multiple lines.
<html>
<head>
<body>
<h1>
<?php
/*This is
an example of
Multi line comments
in PHP.*/
echo "Hello there!";
?>
</h1>
</body>
</html>
Output
Hello there!
3. Shell/Perl Style single line Comments. (#)
These kind of comments start with
# and cannot span across multiple lines.
<html>
<head>
<body>
<h1>
<?php
echo "Hello there!"; #Perl/Shell style Single line comments.
?>
</h1>
</body>
</html>
Output
Hello there!