In the 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
Single-line PHP Comments To leave a single-line comment, type two forward slashes (//) followed by your comment text. All text to the right of the // will be ignored. You can also use a hash symbol (#) instead of // to make a single-line comment.
To “comment out” in HTML, simply place the < ! ╌ ╌> tags around the code you want to hide. These tags will tell browsers not to render this code on the front end. Commenting out has two main purposes.
Multiline Comments You can comment multiple lines by the special beginning tag <! -- and ending tag --> placed before the first line and end of the last line as shown in the given example below.
HTML <!--...--> Tag The comment tag is used to insert comments in the source code. Comments are not displayed in the browsers. You can use comments to explain your code, which can help you when you edit the source code at a later date. This is especially useful if you have a lot of code.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With