Page 1 of 1

using php to convert line breaks to HTML

Posted: Thu Oct 31, 2002 7:28 am
by Geomancer
:?:

Hi,
I have a problem creating dynamic content of my webpage.
I want to get text by a texfield, store it in a database and display it on my homepage by a php-script. The inserting, storing and displaying works quite fine, but there are no line breaks shown.
i guess i have to convert the line breaks to the HTML-Tag <BR>:

I'm a newbie to php and would by happy to get some lines of code, so i can display text with proper line breaks in my browser.

Posted: Thu Oct 31, 2002 7:30 am
by twigletmac
You need to use nl2br().

So if previously you were doing:

Code: Select all

echo $text;
to get those HTML linebreaks you just need to do:

Code: Select all

echo nl2br($text);
Mac