Page 1 of 1

Keep formatting

Posted: Wed Aug 21, 2002 3:52 pm
by ace2600
I have a multiline text field in a form thats information is sent to my db. When a user views a page that outputs the db with echo "$multiline"; the line breaks the user originally put in are not there.
Is this because the db only keeps the text not formatting or because the echo command doesnt preserve the formatting?
More importantly, how do I display the info the user typed, how he typed it?
Thank you,
Ace

Posted: Wed Aug 21, 2002 3:58 pm
by volka
check nl2br

Posted: Wed Aug 21, 2002 5:15 pm
by gotDNS
If I input:
Bla

Bla bla

bla
into a textbox named 'bob'.

So you usually see: "BlaBla blabla" when u echo $bob. In the database, it is multiline....but yeah..it doesn't preserve it...

TO DO THIS: suppose you extract the contents of what you want from ur database and u put it into a variable called '$bob'

Code: Select all

$search = array("/\n/");
$replace = array("<br />\n");
$multilinebob = preg_replace($search, $replace, $bob);
then when you echo $multilinebob, you get a multiline version....you could ASLO do this with spaces if you want...make it replace ' ' with '&nbsp;'

hope i helped....

later on, -Brian

Posted: Thu Aug 22, 2002 1:23 am
by Takuma
Never knew there was a function called "nl2br". It's realy usefull :!: Thanks