首页 > 解决方案 > 如何使用php打印存储在变量中的“<”和“>”?

问题描述

<form id="preview-form" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  <textarea class="codemirror-textarea" name="preview-form-comment" id="preview-form-comment"><?php echo $comment;?></textarea>
  <br>
  <script type="text/javascript" src="js/jquery.min.js"></script>
  <script type="text/javascript" src="js/default.js"></script>
  <input type="submit" onclick="savedata();" name="preview-form-submit" id="preview-form-submit" value="Submit">
</form>

当我echo $_POST['preview-form-comment'];在 PHP 脚本中执行并且 textarea 中的文本#include<stdio.h>时,它只打印#include并将另一部分作为标签。

标签: phphtml

解决方案


htmlspecialchars()会做的。

试试看echo htmlspecialchars($_POST['preview-form-comment'])


推荐阅读