Page 1 of 1

Problem with echo'ing text onto a site

Posted: Thu Sep 09, 2004 10:46 am
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,

nl2br

Posted: Thu Sep 09, 2004 11:05 am
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

Posted: Thu Sep 09, 2004 11:12 am
by Archy
Cool, it works nicely

Cheers, Archy : )