If you are a PHP web developer, then, you surely want to build any web program using the PHP programming language. But, what about the complexity of the project? Will it be complex and would it be easy to debug them in future? Well, the answer to this will be about how you have built up that project. To make your PHP project much easy, one of the method on it would be by writing the comments to the respective function would be a great way to program your PHP code, since, if you add comments, then, you can remember that what is that function being built for in the future.
Well, after knowing the importance of PHP comments, you might need to know about how to add the comments in your PHP project. Hence, here, we are describing the different way to write the PHP comments. Also, it is a way to remember that what a function does, even after a year and more. So, writing a PHP comments is great. Also, the other thing is that, the PHP comments are not displayed in the HTML output file. The advantage of this would be, that the visitors will not know anything about how certain function is build and its functionality for the specific website. There are two ways to write a PHP comments, which are described below:
Single Line Comment
It is the comment written in PHP which only affects the single line after the comment syntax is written. These are of two types:
The basic syntax for // and # is provided below respectively:
// This is single line comment, you must use it for only one line, if you skip to next line, it does not work and PHP reads it as other processes
# This is single line comment, you must use it for only one line, if you skip to next line, it does not work and PHP reads it as other processes
Double Line Comment
It is the comment written in PHP which affects two or more than two lines after the comment syntax is written. The basic syntax is provided below:
* This is double line comment
* You can write again and again here
* This can also be used as the documentation
The example for the PHP comment in the HTML document file is provided below:
<title>Comments in PHP</title>
<h1>Comments in PHP</h1>
echo "Hello World!<br />";
echo "PHP comments can't be seen in either output result or in HTML output";
// This is a single line comment, which is used more, ie very common
# This is also a single line comment, which is used less
* This is a multiple lines comment block
* that can be used in more than
* one line
The above image shows the details on the output for the above PHP code comments, when it is executed. Here, in the above image, the top one is of the outputted data in browser, and the below one is of the whole source code outputted in HTML format from the above PHP code. Here, you can see that the PHP comments has been removed from the output window as well as from the outputted HTML format.
Now, if you have followed the above example properly in your development environment or in your PHP project, then, we can assume that you have learnt about writing comments in PHP progrmming language and will follow this in your developing or developed PHP projects.