Author Topic: Newline in a database  (Read 168 times)

0 Members and 1 Guest are viewing this topic.

Offline astupiduserTopic starter

  • Irregular
    • View Profile
Newline in a database
« on: February 08, 2010, 05:49:53 PM »
Hi,

I have the following issue:
I have a form (textarea), where my user writes a text (e-mail). There are of course some newlines in it. I have to save it in a database and then read it and send it as an e-mail (function mail). The problem is, when I do that all the newlines get somehow stripped and my e-mail has only one line and looks ugly. When I read it and put itt back in the textarea, it looks as it should but not when I mail it. Does anybody have a solution?

Regards,
astupiduser

Online premiso

  • Life is too short
  • Freak!
  • Gender: Male
  • Liquid luck is Jack Daniel's
    • View Profile
Re: Newline in a database
« Reply #1 on: February 08, 2010, 06:12:08 PM »
Before you add it to the body of the email call nl2br() on the data to convert newline characters to their html equivalent <br />

Offline astupiduserTopic starter

  • Irregular
    • View Profile
Re: Newline in a database
« Reply #2 on: February 12, 2010, 07:48:10 PM »
Thanks a lot, it works!  :thumb-up:

Offline thorpe

  • Staff Alumni
  • 'Mind Boggling!'
  • *
    • View Profile
Re: Newline in a database
« Reply #3 on: February 12, 2010, 07:56:08 PM »
You should actually use the nl2br() function on the way out of the database, not the way in.
Patience is like bread I say, I ran out of that yesterday.

Debian :: Funtoo :: Hudzilla :: Rute :: How To Ask?

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.