Setup Menus in Admin Panel

  • No products in the cart.

  • LOGIN

Comments

Comments in PHP are similar to comments that are used in HTML. The PHP comment syntax always begins with a special character and all text that appears between the start of the comment and the end will be ignored.

Comment’s main purpose is to serve as a note to you, the web developer or to others who may view your website’s source code. However, PHP’s comments are different in that they will not be displayed to your visitors. The only way to view PHP comments is to open the PHP file for editing. This makes PHP comments only useful to PHP programmers. It will make easier to remember for further use.

Suppose you have forgotten what an HTML comment looked like, see an example below which will show you how to write a comment in HTML.

Code:
<!– This is a Comment –>
In PHP, We can represent comment in two formats i.e single line comment and multiple line comments.

Single line comment:

The single line comment tells the interpreter to ignore everything that occurs on that line to the right of the comment. To do a single line comment type “//” or “#” and all text to the right will be ignored by PHP interpreter.

PHP Code:

<?php 
echo "Hello World!"; // This will print out Hello World! 
echo "<br />You can't see my PHP comments!"; // 
echo "nothing"; // 
echo "My name is Rajesh!";
# echo "I am learning PHP"; ?>

Result:

Hello World! You can't see my PHP comments!

Note:-

Here, 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.

 

Multiple line comment:

Similiar to the HTML comment, the multi-line PHP comment can be used to comment out large blocks of code or writing multiple line comments. The multiple line PHP comment begins with ” /* ” and ends with ” */ “.

Code:

<?php
/* Here you are learning Php comments. */
echo "Hello World!";
/* echo "Welcome to php programming language.";
echo "Here you will learn php from beginning.So hurry Up.";
*/
?>

Result:

Hello World!

Note:-

In the above PHP code we got the result “Hello World!” and the rest is as multiple lines commenting section.

ASSIGNMENT : Give examples for single and multiple line comments. MARKS : 10  DURATION : 1 week, 3 days

SEE ALL Add a note
YOU
Add your Comment
 

Advanced Course Search Widget

Popular Courses

Course Categories

© PHPhelp. 2002 - 2018 All rights reserved.
X