Page 1 of 1

My PHP site doesn't show the paragraphs of my database texts

Posted: Fri May 05, 2006 12:36 pm
by indiodoido
Hi
I’ve just developed a php page that gets texts from a mysql database and displays them on the site, but my problem is that it doesn’t show the paragraphs I make.
The texts are uploaded to the database with a form.

Can anyone help me?

Posted: Fri May 05, 2006 12:40 pm
by timvw
Basically, you are experiencing that newlines are not displayed? It's a very common problem and it's because html is rendered differently than plaintext. The easiest solution would be to use http://www.php.net/nl2br before you output the data...

Posted: Fri May 05, 2006 12:48 pm
by indiodoido
hi timvw, tnx for the fast reply.

How do i use nl2br ?
I have a form that sends the text to the database, must i apply the nl2br in that form, or only in the php page that displays the text?

Posted: Fri May 05, 2006 12:53 pm
by Deemo
you could do either, it doesnt really matter. Both ways will return the string with all \n changed to <br>

heres the manual entry for more info: nl2br

Posted: Fri May 05, 2006 1:02 pm
by indiodoido
hi Deemo

I'm really new to php :( and i don't understand how to apply nl2br()

this is the code that gets the text from the database: <?php echo $row_rec_empresa_b['texto']; ?>
how do i apply nl2br() ?

Posted: Fri May 05, 2006 1:31 pm
by Hurreman

Code: Select all

<?php echo nl2br($row_rec_empresa_b['texto']); ?>

Posted: Fri May 05, 2006 1:42 pm
by indiodoido
tnx timvw, Deemo and Hurreman...

IT'S WORKING...TNX ALOT GUY'S :wink: