Vin*_*nce 4 html php mysql database tags
我一直在努力弄清楚如何在mysql表中显示html标签.我已经尝试使用addslashes,mysql_real_escape_string以及stripslashes来正确查看标签.每次我通过浏览器查看数据时,它都会显示html的文本.例:
我在mysql数据库表中有这个:
<strong>Test</strong>
Run Code Online (Sandbox Code Playgroud)
在网页上查看时应显示为: 测试
但相反,它显示 <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>
Run Code Online (Sandbox Code Playgroud)
Siy*_*iao 34
替换以下行
echo(stripslashes($row['details'])); //The details is what contains the <strong>Test</strong>
Run Code Online (Sandbox Code Playgroud)
同
echo htmlspecialchars_decode(stripslashes($row['details'])); //The details is what contains the <strong>Test</strong>
Run Code Online (Sandbox Code Playgroud)