MySQL选择[重复]后没有换行符

This question already has an answer here:

I've a MySQL database with some posts in (with linebreaks).

I select these by using this syntax:

public function getById($id) {
    $stmp = $this->_db->prepare("SELECT `content` FROM `posts` WHERE `id`= ?;");
    $stmp->execute(array($this->id));
    $row = $stmp->fetch(PDO::FETCH_ASSOC);
    $this->content = $row['content'];
}

But this way I lose the linebreaks. Is there a way that I can select the content included the linebreaks?

Sincerely,

LuxoJr

</div>

Newlines in the database are saved as (newline) or (return) or a combination of those two. At the client side the webbrowser ignores those, thats why you dont see them, the only way to do that is converting them to <br/> (breaks)

Converts (, , , ) to <br/>

nl2br($row['content']);

see php doc nl2br function

HTML transforms line feeds into spaces. Use this to turn them into visible line feeds in HTML:

$this->content = nl2br($row['content']);