如何注释掉 HTML 文件中的 PHP 行?

发布于 2024-10-10 08:01:40 字数 118 浏览 0 评论 0原文

在我的 HTML 代码中间,有一行 PHP 代码。现在,我想将 PHP 行作为注释。 我尝试使用 但它似乎不适用于 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

滥情空心 2024-10-17 08:01:40

假设你有下面的代码:

<body>
    <?php echo $this_variable_will_echo_a_div; ?>
</body>

如果你想让div回显但不显示在页面上,你会注释html,PHP仍然会被执行:

<body>
    <!-- <?php echo $this_variable_will_echo_a_div; ?> -->
</body>

如果你不希望div出现在注释 html 的源代码中,您必须注释 php,源代码的 body 标记之间不会出现任何内容:

<body>
    <?php /* echo $this_variable_will_echo_a_div; */ ?>
</body>

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>
苍景流年 2024-10-17 08:01:40

PHP语法的所有注释方法都在HTML内的嵌入代码中起作用。
随意使用任何人。

<?php //for one line comment ?>

<?php /* for multi-lines comment */ ?>

您还可以在 php 标签之外使用 HTML 注释语法。

<!-- <?php blah blah ?> --> 

请注意,PHP 代码仍将被执行。

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.

幽梦紫曦~ 2024-10-17 08:01:40

您需要使用 PHP 注释 而不是 HTML 注释

请注意,出于安全原因,在使用 注释掉包含 PHP 代码的 HTML 块时,您应该隐藏 PHP 代码,否则您的源代码将可见当查看页面时。

You need to use PHP Comments not HTML comments <!-- -->

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.

混吃等死 2024-10-17 08:01:40

使用

<?php
/*
    <?php
        php code.. blah blah
    ?>
*/
?>

<?php
    // <?php echo 'hi'; ?>
?>

<?php
    # <?php echo 'hello'; ?>
?>

Use

<?php
/*
    <?php
        php code.. blah blah
    ?>
*/
?>

Or

<?php
    // <?php echo 'hi'; ?>
?>

Or

<?php
    # <?php echo 'hello'; ?>
?>
窗影残 2024-10-17 08:01:40

使用常用的 HTML 注释标签注释掉您想要的任何代码。 php 的 p 和 h 之间加一个空格。出于历史目的,请为将来可能进行任何编辑的任何其他代码作者添加附加注释。
*注意:建议仅在注释掉的代码最终被删除时临时使用。 (我在等待客户批准时使用了它。)

 <!--Nullified php call with spaces between the letters p and h within commented-out html code -->
 <!-- <div class="foo">
                <?p hp require($INC_DIR. "unneeded.php"); ?>
            </div>-->

Comment out whatever code you wish with the usual HTML comment tags. Put a space between the p and h of php. For historical purposes, add an additional comment for any other code author who may do any editing in the future.
*Note: Recommended for temporary use only when the commented out code will eventually be deleted. (I used it while waiting for approval from a client.)

 <!--Nullified php call with spaces between the letters p and h within commented-out html code -->
 <!-- <div class="foo">
                <?p hp require($INC_DIR. "unneeded.php"); ?>
            </div>-->
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文