javascript - htmlspecialchars_decode 导致宽度问题

标签 javascript php html css

我一直在搞乱用 PHP 创建东西,所以决定创建一个站点......但是,当我从我的数据库中提取东西时,它正在调整文本大小并将东西推离页面:/

我已经用纯文本进行了测试,我的网站显示正确: http://gentetcreations.co.uk/blog-2.php

但是,对于 HTML 文本,它以一种奇怪的方式显示,我似乎无法修复它: http://gentetcreations.co.uk/blog-1.php

JSFidle here!

<!DOCTYPE HTML>
<html>
<head>
  <title>GentetCreations</title>
  <meta charset="UTF-8">
  <link rel="stylesheet" type="text/css" href="style/style.css" />
</head>
<body>

  <div id="main">
    <?php
    include("inc/pageHead.php");
    ?>
    <div id="site_content">
      <?php
      include("inc/side.php");
      ?>
      <div id="content">
        <?php
        include("inc/dbconnection.php");
        $id = $_GET['id'];
        $id = trim($id);
        $result = mysqli_query($conn, "SELECT * FROM  blog WHERE authorised = 1 AND blog_id = '" . $id . "'"); 
        if(!$result) {
          die("Database query failed: " . mysqli_error($conn));
        } else {
          $rows = mysqli_num_rows($result);
          if ($rows > 0) {
            while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
              $tags = "";
              $result2 = mysqli_query($conn, "SELECT * FROM tags WHERE blog_id = '" . $row['blog_id'] . "'");
              if(!$result2) {
                die("A Database query failed: " . mysqli_error($conn));
              } else {
                while ($row2 = mysqli_fetch_array($result2, MYSQLI_ASSOC)) {
                  $rawTag  = $row2['tag'];
                  $tag = str_replace(" ", "", $rawTag);
                  $tags .= "<a href='tag-" . $tag . ".php'>" . $tag . "</a> ";
                }
              }
              echo "
              <span class='mainContentWidth'>
                <table>
                  <tr>
                    <th>
                      <a href='blog-" . $row['blog_id'] . ".php'>
                        <h2>" . $row['title'] . "</h2>
                      </a>
                    </th>
                  </tr>
                  <tr>
                    <td>
                      <p>" . date("d/m/Y", strtotime($row['createdDate'])) . "</p><br />
                      <span>" . $row['content'] . "</span>
                      <br />
                      <br />
                      <span><small>Tags: " . $tags . "</small></span>
                    </td>
                  </tr>
                </table>
              </span>";
      } //$row = mysqli_fetch_array($result, MYSQLi_ASSOC)
  } else { //$rows > 0
    echo "<br /><h1>An error occurred.</h1><br /><h2>The blog you were looking for could not be found.</h2>";
  }
}
?>
</div>
</div>
<?php
include("inc/footer.php");
?>
</div>
</body>
</html>

我不熟悉基于网络的编码,所以我在这里真的很困惑,不太确定发生了什么。

如果有人能在这里帮助我或插入我朝着正确的方向正确显示所有内容,我将非常高兴!

最佳答案

你有block level span 标签内的元素。你应该避免这样做。

对于当前问题,您可以添加此 CSS

table tr td > span {
  width: 615px;
}

关于javascript - htmlspecialchars_decode 导致宽度问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27126682/

相关文章:

javascript - 使用数组中的参数调用函数 - apply() 而不使用上下文参数?

javascript - Cappuccino :键盘事件在 reCAPTCHA 输入字段中被压缩

php - Symfony 2 : Doctrine Cache Namespace

php 挑战 : parse pseudo-regex

html - CSS:当我需要垂直时水平显示菜单下拉菜单

html - Bootstrap 4 列顺序不适用于移动设备

javascript - 在字符串中查找部分匹配项

php - 获取已购买商品的所有客户的列表

javascript - 如何让两个切换隐藏/显示按钮占据主体中的相同空间?

javascript - 如何将 html 文件包含在另一个 html 文件中