JimmyBanks
JimmyBanks

Reputation: 4728

Data retrieved from database ignoring line breaks

Data that is stored in my mysql database, has the breaks of text input properly, but when retrieved the data no longer has the breaks, and everything is displayed as one string without any <br>. Any idea why this would occur?

The data column is the format text, for example: in a table there is:

hey
how
do
you
do

After retrieving the data ill echo $mesarray[0][message]; and the result is:

hey how do you do

I want the line breaks to appear, but they dont.

Upvotes: 2

Views: 2330

Answers (1)

Starx
Starx

Reputation: 79049

The reason is because HTML does not understand line breaks. They need <br /> tags to break lines.

There is a function called nl2br() which can be used to convert new lines to <br>

echo nl2br($mesarray[0][message]);

Upvotes: 7

Related Questions