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

0 Members and 1 Guest are viewing this topic.

Offline astupiduserTopic starter

  • Irregular
  • Posts: 10
    • 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

Offline premiso

  • Karma Chameleon
  • Staff Alumni
  • Freak!
  • *
  • Posts: 6,669
  • Gender: Female
  • effing right
    • View Profile
    • PHP Help
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
  • Posts: 10
    • 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

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,236
    • 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.