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 (http://www.phpdoc.org/)

Example1: Single Line Comment

<html>
<head>
<title>PHP 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.

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 " */ ".

Example2: Multi line comments

<html>
<head>
<title>PHP 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.



 
SHARE THIS IF YOU LIKE!
submit to reddit

SUBSCRIBE FOR LATEST UPDATES
HAVE WE CONNECTED ON FACEBOOK?
TOP TUTORIALSTOP CODE EXAMPLESTOP LIVE DEMOLINKSSTAY CONNECTED
HTML Tutorial
HTML5 Tutorial
Bootstrap3 Tutorial
Javascript Tutorial
TypeScript Tutorial
AngularJS Tutorial
CSharp Tutorial
PHP Tutorial
Developer Tools
Javascript
AngularJS
Google MAP API V3
ASP.NET
Javascript
AngularJS
Google MAP API V3
Contact Us
Advertise with Us
Privacy Policy
Disclaimer
Stay connected. We actually like you. If you want to get up to the minute updates, then connect with us on your fav below.
 
Twitter   Linkedin   Facebook   Google+    RSS   Pinterest
 
Protected by Copyscape Original Content Checker
 
 
Copyright ©2017 www.techstrikers.com Unauthorized reproduction/replication of any part of this site is prohibited.