在html注释中使用if else endif



我想知道如何使用php函数。If, else,以HTML注释结尾。这是我的示例代码:

<!-- if 1 == 1 -->
 Is equal
 <!-- else -->
 Not equal
 <!-- endif -->

我的php文件将此注释转换为:

<!-- ?> if (1 == 1) <?php -->

使用这个方法安全吗?有任何方法来查看html文件与这个评论从任何用户?

将PHP代码显示到HTML Comments中并不是一个明智的主意。我强烈建议不要这样做,因为您可能会将有价值的应用程序逻辑暴露给未知的用户。

问题是,为什么你想使用PHP代码到HTML注释?

  • 如果你想用它来帮助自己开发,最好只是写伪代码。
  • 如果你想有实际的php代码到你的帮助文件,那么你不需要把它放在HTML注释。像这样:

    <?php if (1 == 1): ?>
        Yes, 1 is equal to 1! Awesome
        place rest of html code here for example.
    <?php else: ?>
        No, 1 is not equal to 1
    <?php endif; ?>
    

最新更新