duangongqiong6958 2018-04-17 16:00
浏览 67
已采纳

使用php显示包含来自数据库的html标签的内容

Table name : Post, column name : content say, below data along with the html tag and style is stored in content column

<h1 style="color:red">test</h1>

I'm using below php code to display it

<?php
$sql = "SELECT content FROM post where id = 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    // output data of each row
  while($row = $result->fetch_assoc()) {

    ?>
    <?php echo htmlspecialchars($row['content'], ENT_QUOTES); ?>
    <?php
  }
}
else {
echo "0 rasdesults";
}
$conn->close();
?>

expectation : test in red color but output : only "test"

  • 写回答

1条回答 默认 最新

  • dongmoxin7111 2018-04-17 16:15
    关注

    Please replace you echo syntaxt

    <?php echo htmlspecialchars($row['content'], ENT_QUOTES); ?>
    

    with below line

    <?php echo htmlspecialchars_decode($row['content']);?>
    

    Hope this will help you! Thanks & regards.
    Shishil Patel

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题