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 */.

4 Responses to “Comments and Comment Blocks in PHP”

  1. miftachul
    November 5th, 2009 22:12
    4

    mau nanya,, bagaimana cara menghubungkan antara script php menjadi script bahasa C. sehingga kita menggunakan php untuk meremote aplikasi berbahasa C. tolong berikan penjelasanya n mungkin referensi lain yang dapat saya cari.

  2. Walter De Vos » Hoe High Quality YouTube Videos embedden
    January 16th, 2009 01:11
    3

    [...] Er is een hack waarmee toch Hoge kwaliteit video kan geïntegreerd worden. Zie How to Embed High Quality and Higher Resolution YouTube Videos on Blog or Website » My Digital Life [...]

  3. 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: [...]

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

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

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 to My Digital Life Comments RSS feed to receive notification of latest comments posted.

New Articles

Incoming Search Terms for the Article

php block comment - PHP Coments - php comment block - php comment out block - php coment - coments in php - how to comment out php - php comment blocks - coment php - comment out php - BLOCK COMMENT PHP - coments php - php comment out - coment in php - comment block php - php block comment coda - html comment blocks - php block comments - comment out in php - php coments - comment out a block of php - block remark in php - how to coment in php - comment out large block of php - php comment out block of code - comment out a block in php - block comment in php - php comment out code - comment out php block - comment out block of php - php commnent - /coment.php - block out php code - add comments in php - add comment php - comenting php - add comment in php - comment out php code - php add comment - comment code block php - commenting out php code - php block remark - comments script php - how to comment out in php - commenting blocks in php - html block comment - comment out block of php code - comment out large block php - comment script php - commenting blocks of code php -