简体   繁体   中英

How to easily commenting PHP+HTML code

Especially for easy and small projects, I leave pure HTML in my PHP source code and I simply add the relevant PHP when needed, and so many times I have something like this:

<div class="header-info">
  <p><?php echo $w["emailText"][$lang];?></p>
</div>

Now, apart from it being good or bad practice, how can I easily comment out the whole 3 lines? If I enclose them in HTML comments like these (sorry for the space but otherwise they are not printed):

 < !-- 
    ... my code ...
 -->

then PHP is still executed. If I enclose them in something like

 <?php
   if (0) {
 ?>
   ... my code ...
 <?php
   }
 ?>

then the nested "?>" will close my PHP if(0).

Again, I am fully aware that I should better use a Model-View-Controller approach and not mix different "worlds", but as said, for small projects it does not make sense and I am just asking if there is another solution to the 2 that I proposed :)

Thank you

If you do not needed, why not remove it completely? If you want to prevent div tag from outputing to browser, then you can comment all of them, like following.

<?php /*
  <div class="header-info">
    <p><?php echo $w["emailText"][$lang];?></p>
  </div>
*/ ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM