htmlspecialchars_decode导致宽度问题

时间:2014-11-25 12:25:03

标签: 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>

我是基于网络编码的新手,所以我真的很困惑,不太确定发生了什么。

如果有人能在这里帮助我或者让我朝着正确的方向正确地展示一切,我会非常高兴!

1 个答案:

答案 0 :(得分:1)

span标记中包含block level个元素。你应该避免这样做。

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

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