How can I comment out PHP lines inside HTML file?
In 开发者_StackOverflowthe middle my HTML code, I have a line of PHP. now, I want to make PHP line as a comment.
I tried to ues <!-- -->
but it seems not work for PHP.
What should I do?
Thanks
Imagine you have the following code:
<body>
<?php echo $this_variable_will_echo_a_div; ?>
</body>
If you want the div to be echoed but not displayed at the page, you'll comment html, PHP still gets executed:
<body>
<!-- <?php echo $this_variable_will_echo_a_div; ?> -->
</body>
If you don't want the div to appear at the source as commented html, you'll have to comment php, nothing will appear between the body tags at your source:
<body>
<?php /* echo $this_variable_will_echo_a_div; */ ?>
</body>
All the commenting methods of PHP syntax works in the embedded code inside HTML. Feel free to use anyone.
<?php //for one line comment ?>
<?php /* for multi-lines comment */ ?>
also you can use the HTML comment syntax just outside the php tags.
<!-- <?php blah blah ?> -->
Note that the PHP code will still be executed.
You need to use PHP Comments not HTML comments <!-- -->
Note that you should hide PHP code for security reasons when commenting out a chunk of HTML containing PHP code using <!-- -->
otherwise your source code will be visible when page is viewed.
Use
<?php
/*
<?php
php code.. blah blah
?>
*/
?>
Or
<?php
// <?php echo 'hi'; ?>
?>
Or
<?php
# <?php echo 'hello'; ?>
?>
Comment out whatever code you wish with the usual HTML comment tags. Put a space between the p and h of php. For historical purposes, add an additional comment for any other code author who may do any editing in the future. *Note: Recommended for temporary use only when the commented out code will eventually be deleted. (I used it while waiting for approval from a client.)
<!--Nullified php call with spaces between the letters p and h within commented-out html code -->
<!-- <div class="foo">
<?p hp require($INC_DIR. "unneeded.php"); ?>
</div>-->
精彩评论