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 */.
Related Articles
- 3 Column Relaxation WordPress Theme comments-paged.php for Paged-Comments WordPress Plugin
- How to Add and Put Picture or Image in MySpace Comment
- How to List and Show WordPress Posts That Comments and Pings Off (Not Allow)
- Fight and Stop Comment Spam and Trackback Spam with Akismet
- Free Download: Akismet for WordPress Plugin 2.0 to Stop Comment, Trackback and Pingback Spam
- Google AdSense Policy Update Disallows Image Besides Ads Blocks
- Reduce Server Load Using Akismet to Automatically Discard Spam Comments on Posts Older than A Month
- Stop Comment, Pingback and Trackback Spam with New Version of Akismet
- Moderate WordPress Blog Comments Via Moderator with Desktop Client
- Integrate WordPress including Comments with bbPress Forum using bbSync










































January 16th, 2009 01:11
[...] 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 [...]
December 10th, 2007 01:30
[...] tip of the hat to My Digital Life for his article – Comments and Comment Blocks in PHP. By Alec Tags: [...]
July 26th, 2006 06:45
[...] http://www.mydigitallife.info/2006/04/26/dis…. [...]