Web Hosting Talk







View Full Version : php mysql newline needed


variable
06-11-2005, 03:06 AM
i am working on a thing for users to enter data into a form, this form is then stored in a database. the only problem is that when the user wants a newline, the code just jumbles together anyhow.

how can put in newlines?

thanks

Burhan
06-11-2005, 03:25 AM
Can you please be a bit more specific? It jumbles up where? When you are displaying it?

variable
06-11-2005, 03:31 AM
say this forum for example, when i hit enter, it goes to a new line. but when i do this and store it to mysql then redisplay it:
this
---------------------
hello all,

how are you?
---------------------
turns into this
--------------------
hello all,how are you?
--------------------

i want a newline when the user hits enter

Burhan
06-11-2005, 05:21 AM
You need nl2br() (http://php.net/nl2br). The browser doesn't understand newlines -- only HTML.

Koobi
06-11-2005, 11:58 AM
And if you do use nl2br(), make sure you don't trim() before you use that because, by default, trim() removes \r and \n which are the new-line characters for different OS's

variable
06-11-2005, 03:49 PM
thanks, works like a charm, i didnt know how to turn php newline into html <br>, and now i do thanks!