Can not display new line character

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
hoangvu.che
Forum Newbie
Posts: 19
Joined: Thu Mar 22, 2007 9:54 pm

Can not display new line character

Post by hoangvu.che »

After retrieving data from MySQL, I display all data on my page (in a <td> tag).
However, the new line character is automatically omitted.

I have checked by filling the data in a textfield, the new line character exists normally.

Please help me how to display the data correctly.

thanks.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

echo '<td>' . nl2br($data) . '</td>';
There are linebreaks (you can see them when viewing generated html via 'View source'), but browsers just ignore them.
hoangvu.che
Forum Newbie
Posts: 19
Joined: Thu Mar 22, 2007 9:54 pm

Post by hoangvu.che »

thanks Weirdan.

it can be solved with nl2br() function.
Post Reply