Welcome Guest, Not a member yet? Register   Sign In
Line breaks? When pulling from the Database
#1

[eluser]JamieBarton[/eluser]
Hey guys,

I'm doing sort of a news system, what is the best way to perform line beaks. My articles in the DB have line breaks, however, when i load the view (below) everything is crammed together. How can I get round this?

controller:
Code:
function article()
    {
        $requested_id = $this->uri->segment(3);
        $data['query'] = $this->db->where('id', $requested_id);
        $data['query'] = $this->db->limit(1);
        $data['query'] = $this->db->get('news');
        
        $this->layout->view('news/article', $data, array('page_name' => "news"));
    }

view:
Code:
<div id="main">

    &lt;?php if ($query->num_rows() > 0) { $row = $query->row(); ?&gt;
    
        <h2>&lt;?=$row->title?&gt;</h2>
        
        <p>&lt;?=$row->body?&gt;</p>
    
    &lt;?php } else { ?&gt;
    
    <h2>Not found</h2>
    
    <p>Sorry, we couldn't find the news article you were after.</p>
    
    &lt;?php } ?&gt;
    
</div>


Regards,

Jamie
#2

[eluser]imn.codeartist[/eluser]
If your line break is \n then use the below code
Code:
<p>&lt;? echo nl2br($row->body)?&gt;</p>
#3

[eluser]BrianDHall[/eluser]
You could try replacing "\n" (newline) with <br>. It's the easiest way I know of.

EDIT: dixcoder beat me to it.

Also, there is always the <pre> HTML tag.




Theme © iAndrew 2016 - Forum software by © MyBB