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

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
indiodoido
Forum Newbie
Posts: 7
Joined: Fri May 05, 2006 12:32 pm

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

Post 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?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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...
indiodoido
Forum Newbie
Posts: 7
Joined: Fri May 05, 2006 12:32 pm

Post 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?
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post 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
indiodoido
Forum Newbie
Posts: 7
Joined: Fri May 05, 2006 12:32 pm

Post 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() ?
User avatar
Hurreman
Forum Commoner
Posts: 61
Joined: Sat Apr 29, 2006 8:42 am

Post by Hurreman »

Code: Select all

<?php echo nl2br($row_rec_empresa_b['texto']); ?>
indiodoido
Forum Newbie
Posts: 7
Joined: Fri May 05, 2006 12:32 pm

Post by indiodoido »

tnx timvw, Deemo and Hurreman...

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