Comments and Comment Blocks in PHP

PHP supports C language, C++ programming language and Unix shell-style (Perl style) comments. In PHP, // or # is used to make a single-line comment or /* and */ to make a large comment block that spans several lines.

For example:

<?php

echo ‘This is a test’; //This is a single-line C++ style comment
echo ‘This is another test’;#This is another single-line shell-style comment
/* This is a multi line comment
Second line of comment */

?>

The “one-line” comment styles comment to the end of the line or the current block of PHP code, whichever comes first. This means that HTML code after the PHP script block (PHP mode broken with ?> and returns to HTML mode after end of PHP code block) will be printed. If the asp_tags configuration directive is enabled, it behaves the same with // %> and # %>. However, the </script> tag doesn’t break out of PHP mode in a single-line comment.

For example,

<h1>This is an <?php # echo ’simple’;?> example.<h1>
<p>The header above will say ‘This is an example’.</p>

C or C++ style comments end at the first */ encountered. Any nested /* and */ style comments will cause error, and it’s pretty easy to make this mistake if you are trying to comment out a large block of code.

<?php

/*
echo ‘This is a test’; /* This comment will cause a problem */
*/

?>

The PHP comments is useful when you want to comment or disable a large portion of HTML. Instead comment the HTML code line by line, put the whole HTML block into PHP code block (i.e, add <?php and ?>) and comment with /* and */.

Share and contribute or get technical support and help at My Digital Life Forums.



2 Responses to “Comments and Comment Blocks in PHP”

  1. E-Volution IT » Blog Archive » Windows Genuine Advantage circumvention
    July 26th, 2006 06:45
    1

    [...] http://www.mydigitallife.info/2006/04/26/dis…. [...]

  2. How to Comment Code in WordPress Templates
    December 10th, 2007 01:30
    2

    [...] tip of the hat to My Digital Life for his article - Comments and Comment Blocks in PHP. By Alec Tags: [...]

Leave a Reply

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>

Subscribe without commenting


Custom Search

New Articles

Incoming Search Terms for the Article

php comment - php comment out - comment out php - how to comment out php - php coment - comment in php - comment php - php comment block - php coments - how to comment php - php commenting - comment out php code - coment php - add comment php - coments in php - comment out php script - comment out blocks of html code - how to comment out php code - php block code - php comments - php add comment - php comment blocks - commenting in php - how to comment out in php - how to comment block of code in php? - commenting out php - php commenting out block - php coment manual - php comment blocks of code - how to I comment out php script? - comment block html code class php - comment code block php - how to comment out a block in php - php echo block - php commenting blocks - c++ comment out large blocks - comment out code php - coment out php - comment large blocks of html - how to comment block in html - good comment block in php code - comment out html and php - commenting php - how do I comment out PHP - php block code comment - how to add a comment in PHP - how to comment block of code php - what is a comment block in html - wordpress cool comment blocks - comment out large blocks of c++ code -