php - 如何使用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
并将另一部分作为标签。
解决方案
htmlspecialchars()
会做的。
试试看echo htmlspecialchars($_POST['preview-form-comment'])
推荐阅读
- python - 写入文件的更好方法?
- python - 如果它们与基于索引的第二个数据帧匹配,则删除数据帧中的行
- python - 在 Python 中打印时如何从数据框的索引中删除空白行
- javascript - 如何调用尚未声明的箭头函数
- ssl - 有没有办法使用 prometheus 监控 kubernetes 中的 tls 证书?
- ios - 在视频上覆盖文本非常慢,任何更快的替代方案
- android - 当我尝试将文本和图像发送到 whatsapp 等其他应用程序时,Intent.EXTRA_TITLE 不起作用
- discord - 在 discord.py 中查找谁删除了消息
- php - 使用 preg_replace 在 PHP 中识别和替换字符串中的短编码变量对
- c# - 字典键的协方差