首页 > 解决方案 > 如何注释掉带有 PHP 的 HTML 行?

问题描述

我知道答案很简单,但我在任何地方都找不到。如何禁用这条线?我试过了,但 id 不起作用

// 
<!-- -->
/* */

<a class="switch" data-mode="<?php echo Session::cookieExists("myTheme", "dark") ? "dark" : "light";?>">

标签: phphtml

解决方案


<?php
// <-- this is a comment in PHP, java and javascript (prob others) - NOT HTML
/* this is also a type of comment in PHP, java, javascript and css (and prob others) */
?>

<!-- This is an html comment 
   The PHP code inside it will still run, but the result will be commented out. --> 
<!-- <a class="switch" data-mode="<?php echo Session::cookieExists("myTheme", "dark") ? "dark" : "light";?>"> -->


<!-- This is the element with the PHP code inside commented out -->
<a class="switch" data-mode="<?php /* echo Session::cookieExists("myTheme", "dark") ? "dark" : "light"; */ ?>">

推荐阅读