using php to convert line breaks to HTML

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Geomancer
Forum Newbie
Posts: 1
Joined: Thu Oct 31, 2002 7:28 am

using php to convert line breaks to HTML

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply