【问题标题】:I want to display <!DOCTYPE html> on my site as a string [duplicate]我想在我的网站上显示 <!DOCTYPE html> 作为字符串 [重复]
【发布时间】:2018-12-26 01:15:15
【问题描述】:

&lt;!DOCTYPE html&gt; 没有显示在我的网站上,我有一个包含 html 和 php 问题的简单网站。当我从数据库中呈现问题时,&lt;!DOCTYPE html&gt; 将在 input 或 textarea 中显示,但如果不使用 input 字段,它将不显示任何内容。

这是不显示 html 代码的问题:

这里我在声明中添加了:

【问题讨论】:

  • htmlspecialchars
  • 请学会自己做一些基础研究……在 Google 中输入“我如何在我的网站上将 html 显示为文本”之类的琐碎内容可能会让您立即找到该副本。
  • !DOCTYPE html>

标签: php html


【解决方案1】:

在从数据库中输出数据之前使用htmlspecialcharshtmlentities

<?php echo htmlspecialchars($string); ?>

<?php echo htmlentities($string); ?>

参考

PHP Manual - htmlentities
PHP Manual - htmlspecialchars

【讨论】:

    【解决方案2】:

    在输出之前对您的内容进行编码:

    <?= htmlspecialchars($questionContent); ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-13
      • 1970-01-01
      • 2017-10-02
      • 1970-01-01
      • 2021-04-29
      • 2012-03-25
      • 2018-06-02
      • 2015-09-23
      相关资源
      最近更新 更多