Thursday, March 16, 2017

Should I store the textarea's new lines as in MySQL databes or not?

I am clueless what is the good way.

If I have the content of a textarea like this:

Hi,

I would like to offer you these things:

1) Car
2) Book
3) Airplane

And some other things as well.

Sincerely,
Tim

Should I save the content as it is (after sanitizing malicious code etc.) and then use nl2br() when outputing into html view?

Or I should use nl2br() before saving into db and then just call it in the view as it is saved in the db, in this case:

Hi,<br>
<br>
I would like to offer you these things:<br>
<br>
1) Car<br>
2) Book<br>
3) Airplane<br>
<br>
And some other things as well.<br>
<br>
Sincerely,<br>
Tim<br>

I would like to know what approach is the best from the db point of view (less space taken, faster, etc.) and what is more universal (using it later for emails, parsing, etc.)

If I look at it from my point of view, it's better to use 1 nl2br() function when saving instead of many nl2br() functions during the rendering in my html view.

What is your take on this "dilemma"?



via John Doeherskij

Advertisement