Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I comment out PHP lines inside HTML file?

Tags:

comments

html

php

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

like image 369
Hesam Avatar asked Dec 30 '10 09:12

Hesam


People also ask

How do I comment out a PHP in HTML?

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.

Can you comment out lines in HTML?

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.

How do you comment multiple lines of code in HTML?

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.

How do you comment inside HTML?

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.


2 Answers

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>
like image 78
acm Avatar answered Sep 20 '22 18:09

acm


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.

like image 27
Dhiraj Pandey Avatar answered Sep 17 '22 18:09

Dhiraj Pandey