Hey everyone, I'm using the php function nl2br() to display some characters on a page from a textarea. I'm storing the text into the database exactly as it is entered, and then only using the nl2br() when displaying it on a page.

Should I do it the other way around? Should I use nl2br() before I store it to the database, so it is stored that way, or should I just do it how I'm doing it? It really doesn't matter to me, I was just wondering if there is a proper, more recommended way to do it.
Thanks.

Recommended Answers

All 2 Replies

Member Avatar for Rhyan

For as much as I remember nl2br replaces the new lines ascii symbols in text area with the html <br /> tag.
In my opinion you should use the nl2br before posting to the DB as if you don't, the text may be stored as part of the same paragraph.
Later on when extracting the data from the DB you can always remove the <br /> tags with spaces or whatsoever.

Good luck

For as much as I remember nl2br replaces the new lines ascii symbols in text area with the html <br /> tag.
In my opinion you should use the nl2br before posting to the DB as if you don't, the text may be stored as part of the same paragraph.
Later on when extracting the data from the DB you can always remove the <br /> tags with spaces or whatsoever.

Good luck

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.