comment php code in html code example
Example 1: comment in php
A nice way to toggle the commenting of blocks of code can be done by mixing the two comment styles:
<?php
if ($foo) {
echo $bar;
}
sort($morecode);
?>
Now by taking out one / on the first line..
<?php
sort($morecode);
?>
..the block is suddenly commented out.
This works because a /* .. */ overrides //. You can even "flip" two blocks, like this:
<?php
if ($foo) {
echo $bar;
}
?>
vs
<?php
if ($bar) {
echo $foo;
}
?>
Example 2: comment in php
Be careful when commenting out regular expressions.
E.g. the following causes a parser error.
I do prefer using # as regexp delimiter anyway so it won't hurt me ;-)
<?php
/*
$f->setPattern('/^\d.*/');
*/
?>