如何注释掉 HTML 文件中的 PHP 行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4561583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I comment out PHP lines inside HTML file?
提问by Hesam
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.
在我的 HTML 代码中间,我有一行 PHP。现在,我想将 PHP 行作为注释。我尝试使用,<!-- -->
但它似乎不适用于 PHP。
What should I do?
我该怎么办?
Thanks
谢谢
回答by acm
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:
如果您希望 div 被回显但不显示在页面上,您将注释 html,PHP 仍然会被执行:
<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:
如果您不希望 div 在源代码中显示为带注释的 html,则必须注释 php,源代码的 body 标记之间不会出现任何内容:
<body>
<?php /* echo $this_variable_will_echo_a_div; */ ?>
</body>
回答by Dhiraj Pandey
All the commenting methods of PHP syntax works in the embedded code inside HTML. Feel free to use anyone.
PHP 语法的所有注释方法都在 HTML 中的嵌入代码中起作用。随意使用任何人。
<?php //for one line comment ?>
<?php /* for multi-lines comment */ ?>
also you can use the HTML comment syntax just outside the php tags.
您也可以在 php 标签之外使用 HTML 注释语法。
<!-- <?php blah blah ?> -->
Note that the PHP code will still be executed.
请注意,PHP 代码仍将被执行。
回答by Sarfraz
You need to use PHP Commentsnot HTML comments <!-- -->
您需要使用PHP 注释而不是 HTML 注释<!-- -->
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.
请注意,在注释掉包含 PHP 代码的 HTML 块时,出于安全原因,您应该隐藏 PHP 代码,<!-- -->
否则在查看页面时您的源代码将是可见的。
回答by Erik
Use
用
<?php
/*
<?php
php code.. blah blah
?>
*/
?>
Or
或者
<?php
// <?php echo 'hi'; ?>
?>
Or
或者
<?php
# <?php echo 'hello'; ?>
?>