質問

In database, field looks good, but when this field is shown in webapp, blank characters appears before content that I read from database. 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/

content in database: 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();
              }
          }
役に立ちましたか?

解決

Don't use white space in your <pre> tag

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>

他のヒント

You should use trim this way:

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

Don't use whitespace in your <code> tag, and use trim, like this:

<code class="language-cpp"><?php echo trim($query->content); ?></code>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top