Problem with echo'ing text onto a site

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
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Problem with echo'ing text onto a site

Post by Archy »

Whenever I add information into a page (for instance, a news page), All of the line breaks that I wanted to be there dissapear, and so all get merged into one another.

E.g.

Thanks for coming, see you soon
Some Name


would turn into

Thanks for coming, see you soonSome Name

I have 2 ways of entering the text into the MySQL database, I can either add it in manually, or do it from the Admin CP panel I coded. Either way, the text always seems to get de-linebreaked. The only way I can space the text out is to use <br>, and this option is no good, since I am trying to make the site for a person with little programming / Internet knowledge.

Any help would be nice, whether to change the way I store it in the MySQL database (at the moment I am using the TEXT option) or to changing the way that it is outputted (at the moment I am using echo"$variable";)

Thanks,
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

nl2br

Post by phpScott »

you can use nl2br to create the <br /> that you are looking for
http://uk2.php.net/nl2br
in the manual, lots of comments and suggestions to.

some suggestions where to only use nl2br when displaying the data on a web page that way you don't lose the orginal formating when you go to re-edit the text.

javascript use \r or \n or both to create the new lines where html of course uses <br />

phpscott
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

Cool, it works nicely

Cheers, Archy : )
Post Reply