How to use comments in php

November 29, 2011 Posted in PHP Author:adton

How to use comments in php?This article will give you the right answer.

PHP supports ‘C’, ‘C++’ and Unix shell-style (Perl style) comments.

For inline comment(continuous single-line),use // or #.Using # is discouraged.

For block comments(multi-line),use /* */ to make a large comment block

Inline Comment Example:

<?php
echo "This is inline comment.";//This is inline comment with "//"
echo "This is another type of inline comment.";# This is inline comment with "#"
echo "You also can use block comments in a single line.";/*Single line also can use*/
?>

This will output:

This is inline comment.This is another type of inline comment.You also can use block comments in a single line.

Block Comments Example:

<?php
echo "This is multi-line comments.";
/*
This is multi-line comments
or block comments
it will not be displayed for this three lines.
*/
//Inline Comment 1
//For a few lines can also use several inline commets.
?>

This will output:

This is multi-line comments.

Block Comments/text Comment Example:

<?php
/*
 * @version        1.0
 * @package        adtonCMS
 * @copyright      Copyright adton.com
 * @license        http://help.adton.com/license.html
 * @link           http://www.adton.com
 */
// you can use this style to comment your php project.
?>

This will output nothing.

PHP comment Tips:

if you want to comment php scritpts which contains php opening tag

<?php

and closing tag

?>

,do not use inline comment // or #,just use block comments /* */ even if your comment only one line.

PHP Code:

<?php
/*<?php echo "comment php scritpts which contains php opening and closing tags" ?>*/
echo "Welcome to adton.com!";
/* echo "This is block comments!";
echo "<?php echo "This line will not be executed"?>";
*/
?>

This will output:

Welcome to adton.com!
Tags: ,

Random Posts:

Add your comment below,or TrackBack from your own site. You can also subscribe to these comments via RSS2.0 feed.

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*

Back to Top ↑