【发布时间】:2014-05-15 21:59:32
【问题描述】:
在数据库中,字段看起来不错,但是当此字段显示在 webapp 中时,我从数据库中读取的内容之前会出现空白字符。当我打印查询内容时,此字段显示为没有空白字符。有什么解决这个问题的建议吗?
网络应用上的内容: http://postimg.org/image/bxz6k7yzz/
数据库内容:http://postimg.org/image/siix0jrdf/
我在这里打印内容。
<div id="algcode">
<pre>
<code class="language-cpp">
<?php echo $query->content; ?>
</code>
</pre>
</div>
在模型中:
$query = $this->db->query($sql2);
if ($query->num_rows()>0) {
return $query->row();
}
在控制器中:
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();
}
}
【问题讨论】:
-
您是否尝试过在回显
$query->content时使用trim()? -
我得到 FATAL ERROR: Fatal error: Call to a member function trim() on a non-object
-
trim();不是真正的对象,所以你可能用错了 -
没有必要进行修剪,因为@goksiii 已经表明没有空格可以从数据库中修剪。相反,
<pre>包括您的空白和制表符。请看下面我的回答。这就是他们在codefleet 代码格式化程序上使用的东西。
标签: php html sql codeigniter