简体   繁体   English

PHP:数据库中的内容未正确显示

[英]PHP: content from the database isn't displayed correctly

In database, field looks good, but when this field is shown in webapp, blank characters appears before content that I read from database. 在数据库中,该字段看起来不错,但是当该字段显示在webapp中时,在我从数据库读取的内容之前会出现空白字符。 When I print content of query, this field is shown wihtout blank characters. 当我打印查询内容时,此字段显示为空白字符。 Any suggestions to resolve this problem? 有解决此问题的建议吗?

content on web app: http://postimg.org/image/bxz6k7yzz/ 网络应用程序上的内容: http : //postimg.org/image/bxz6k7yzz/

content in database: http://postimg.org/image/siix0jrdf/ 数据库中的内容: http : //postimg.org/image/siix0jrdf/

Here I print content on in view. 在这里,我在视图中打印内容。

                <div id="algcode">
                    <pre>
                      <code class="language-cpp">
                          <?php echo $query->content; ?>
                      </code>
                    </pre>
                </div>

In model: 在模型中:

         $query = $this->db->query($sql2);

         if ($query->num_rows()>0) {
         return $query->row();
         }

In controller: 在控制器中:

          public function searchAlgorithm ($id) {
              $this->load->model('algorithm');
              $this->load->model('comment');

              $algorithm ['query'] = $this->algorithm->getAlgorithm($id);
              if($algorithm['query']!=false) {
                  $algorithm ['id'] = $this->algorithm->getId($id);
                  $algorithm ['comments'] = $this->comment->getComments($id);

                  $this->loadViews($algorithm);
              } else {
                  $this->loadErrorViews();
              }
          }

You should use trim this way: 您应该这样使用trim:

     <div id="algcode">
                    <pre>
                      <code class="language-cpp">
                          <?php echo trim($query->content); ?>
                      </code>
                    </pre>
     </div>

不要在<code>标记中使用空格,而要使用trim,如下所示:

<code class="language-cpp"><?php echo trim($query->content); ?></code>

Don't use white space in your <pre> tag 不要在<pre>标签中使用空格

You have: 你有:

<pre>
  <code class="language-cpp">
    <?php echo $query->content; ?>
  </code>
</pre>

Try this: 尝试这个:

<pre><code class="language-cpp"><?php echo $query->content; ?></code></pre>

Or: 要么:

<pre><code class="language-cpp">
   <?php echo $query->content; ?>
</code></pre>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM