【发布时间】:2013-02-15 16:24:33
【问题描述】:
我一直在试图弄清楚如何在 mysql 表中显示 html 标记。我尝试使用addslashes、mysql_real_escape_string 以及stripslashes 来正确查看标签。每次我通过浏览器查看数据时,它都会显示 html 的文本。示例:
我在 mysql 数据库表中有这个:
<strong>Test</strong>
在网页上查看时应显示如下: 测试
但相反,它显示<strong>Test</strong>
我查看内容的PHP代码是:
<?php
require_once("inc.php"); //This includes the configuration for mysql database
?>
<html>
<head>
</head>
<body>
<p>
<?php
$conn = mysql_connect(HOST,USER,PASS) or die(mysql_error());
mysql_select_db(NAME) or die(mysql_error());
$sql = "SELECT * FROM events";
$query = mysql_query($sql);
while($row = mysql_fetch_assoc($query)){
echo(stripslashes($row['details'])); //The details is what contains the <strong>Test</strong>
}
mysql_close($conn) or die(mysql_error());
?>
</p>
</body>
</html>
【问题讨论】:
-
你用什么代码来显示数据?另外,根据您的问题,您可能应该将 PHP 添加为标签。
-
您使用的框架很可能会自动输出转义以防止 xss 攻击。在我知道的所有框架中,有一种简单的方法可以在不转义的情况下输出字符串。您应该将框架的名称添加到问题中。
-
我正在使用 PHP 来显示数据。
标签: php html mysql database tags