James Pale
James Pale

Reputation: 185

mysql, display text format when echoing out content?

i am trying to echo out the text which is stored in my mysql table, the text in the column 'content' is formated, i.e. has breaks.

for some reason when i echo out the text the text is displaying as one continious result and i want to keep the text format/breaks when echoing it out, is there a way i can do this?

table:

id  |  user  |      content  
1        5          Hello,
                    Hows you today?


2        4          tEXT

php

<?php
$message_set = read_message();
while ($message = mysql_fetch_array($message_set)) { 

<div class="message_content">
<? echo "{$message['content']}"; ?>
</div>

css

.message_content{
    margin-left:90px;
    padding-top:9px;
    padding-right:15px;
    padding-bottom:20px;
}

Upvotes: 0

Views: 632

Answers (2)

Oswald
Oswald

Reputation: 31657

The text is displaying as one continious result, because that's the way how line breaks are treated in HTML by default PHP sends output as HTML to your browser by default. You have to either

  • convert the line breaks to HTML <br> tags (e.g. using nl2br()), or
  • use CSS to style the <div> in such a way that line breaks in HTML are displayed as line breaks in the browser (using the white-space: pre rule), or
  • wrap the query result in <pre> tags.

Upvotes: 3

Justin Bicknell
Justin Bicknell

Reputation: 4808

As of css3 you can break on new line characters:

css:

white-space:pre-line

https://developer.mozilla.org/en-US/docs/CSS/white-space

Upvotes: 0

Related Questions