0% found this document useful (0 votes)
4 views7 pages

PHP Comments

php comment for clean programming experience

Uploaded by

rotichbravin13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

PHP Comments

php comment for clean programming experience

Uploaded by

rotichbravin13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

7/17/25, 4:46 PM PHP Comments

 Tutorials  Exercises  Services   Get Certified

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

PHP Comments
❮ Previous Next ❯

Comments in PHP
A comment in PHP code is a line that is not executed as a part of the program. Its only purpose is to
be read by someone who is looking at the code.

Comments can be used to:

Let others understand your code


Remind yourself of what you did - Most programmers have experienced coming back to their
own work a year or two later and having to re-figure out what they did. Comments can remind
you of what you were thinking when you wrote the code
Leave out some parts of your code

PHP supports several ways of commenting:

Example Get your own PHP Server

Syntax for comments in PHP code:

// This is a single-line comment

# This is also a single-line comment

https://www.w3schools.com/php/php_comments.asp 1/7
7/17/25, 4:46 PM PHP Comments

/* This is a
 Tutorialscomment
multi-line  Exercises
*/  Services   Get Certified

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
Try it Yourself »

Single Line Comments


Single line comments start with // .

Any text between // and the end of the line will be ignored (will not be executed).

You can also use # for single line comments, but in this tutorial we will use // .

The following examples uses a single-line comment as an explanation:

Example
A comment before the code:

// Outputs a welcome message:


echo "Welcome Home!";

Try it Yourself »

Example
A comment at the end of a line:

echo "Welcome Home!"; // Outputs a welcome message

Try it Yourself »

https://www.w3schools.com/php/php_comments.asp 2/7
7/17/25, 4:46 PM PHP Comments

Comments
 Tutorials  to Ignore
Exercises  Code
Services   Get Certified

HTML
We can CSS JAVASCRIPT
use comments SQL linesPYTHON
to prevent code JAVA
from being executed: PHP HOW TO W3.CSS C

Example
Do not display a welcome message:

// echo "Welcome Home!";

Try it Yourself »

?
Exercise
Which one is NOT a legal PHP comment:

# comment goes here

// comment goes here

'' comment goes here

/* comment goes here */

Submit Answer »

❮ Previous Next ❯

https://www.w3schools.com/php/php_comments.asp 3/7
7/17/25, 4:46 PM PHP Comments

 Tutorials  Exercises  Services   Get Certified

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

ADVERTISEMENT

https://www.w3schools.com/php/php_comments.asp 4/7
7/17/25, 4:46 PM PHP Comments

 Tutorials  Exercises  Services   Get Certified

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

COLOR PICKER

 

ADVERTISEMENT

ADVERTISEMENT

https://www.w3schools.com/php/php_comments.asp 5/7
7/17/25, 4:46 PM PHP Comments

 Tutorials  Exercises  Services   Get Certified

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

 PLUS SPACES

GET CERTIFIED FOR TEACHERS

FOR BUSINESS CONTACT US

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference

Top Examples Get Certified


HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
W3.CSS Examples PHP Certificate
https://www.w3schools.com/php/php_comments.asp 6/7
7/17/25, 4:46 PM PHP Comments
Bootstrap Examples jQuery Certificate

 Tutorials  PHP Examples


Exercises 
Java Examples
Services   Java Certificate
Get Certified
C++ Certificate
XML Examples C# Certificate
HTML
 CSS jQuery
JAVASCRIPT ExamplesSQL PYTHON JAVA PHP XMLHOW
Certificate
TO W3.CSS C

    

FORUM ABOUT ACADEMY


W3Schools is optimized for learning and training. Examples might be simplified to improve reading and
learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full
correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and
privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

https://www.w3schools.com/php/php_comments.asp 7/7

You might also like