break into separate lines (solved)

Codes here !

Moderators: egami, macek, gesf

Post Reply
unisabilly
New php-forum User
New php-forum User
Posts: 19
Joined: Wed Aug 17, 2005 6:00 am

Thu May 04, 2006 12:42 pm

I have a little question here ...
I enter the following paragraph into the database (mysql datatype = text):

this is a line
this is an other line
this is the third line

if i select the paragraph out from the database and display it with
echo, it will display the whole thing in one line, so the outcome will look like
"this is a line this is an other line this is the third line"
the question is how can i add <br> to the end of each line so that it will break into separate lines~
Last edited by unisabilly on Fri May 05, 2006 2:21 pm, edited 1 time in total.

Coditor
New php-forum User
New php-forum User
Posts: 243
Joined: Wed Feb 01, 2006 9:18 am
Location: Netherlands
Contact:

Thu May 04, 2006 11:54 pm

If the data from your database contains newlines, you can use <pre> to display it properly. Or you could convert those newlines to breaks:

Code: Select all

<?php
   $text = preg_replace('!\n!', '<br />', $text);
?>
Coditor

unisabilly
New php-forum User
New php-forum User
Posts: 19
Joined: Wed Aug 17, 2005 6:00 am

Fri May 05, 2006 2:20 pm

i found a function which can solve this question : nl2br( ) :D

Post Reply