[SOLVED] Format Text

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

[SOLVED] Format Text

Post by AliasBDI »

I am pulling a record from a database which looks like this:
John jumped over the moon.

John tripped when landing.
When I echo this result it looks like this:
John jumped over the moon. John tripped when landing.
I was wondering if there was a way for PHP to treat the returns in the record as <br> tags or hard returns in HTML. I didn't want to have to go and place <br> tags in the records. Here is my echo:

Code: Select all

<?php
echo $row_detailsArticle['content']; 
?>
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

nl2br

when inserting into the database use this to detect line breaks in textfields

Code: Select all

$text = nl2br($text)
hten when it is retrieved it will format it in the way you describe
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Post by AliasBDI »

Perfect. Thanks!
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

no problem
Post Reply