saving paragraphs in multiline to mysql
Moderator: General Moderators
saving paragraphs in multiline to mysql
This might seem like a really silly question but how can i keep the format of posted text into a mysql database. e.g. i have a multiline textarea as part of a form. When i post this form to my php script I am saving all the data into the mysql database. However if the user makes carrage returns or copies text into the textarea that has paragraphs, I want to keep these paragraph format and saved into the database so i can echo out to a page and retain the format.
- iankent
- Forum Contributor
- Posts: 333
- Joined: Mon Nov 16, 2009 4:23 pm
- Location: Wales, United Kingdom
Re: saving paragraphs in multiline to mysql
it should by default. a newline is represented by \n in a string, and that should be retained when you write it to the database.
if you output it as HTML then it'll look as though its been lost, as \n is ignored as a new line in HTML. you'd need to replace new lines with <br /> using something like str_replace. if you output it inside another textarea then you should see the newlines intact
hth
if you output it as HTML then it'll look as though its been lost, as \n is ignored as a new line in HTML. you'd need to replace new lines with <br /> using something like str_replace. if you output it inside another textarea then you should see the newlines intact
hth
Re: saving paragraphs in multiline to mysql
thanks works a treat i used the nl2br function
- iankent
- Forum Contributor
- Posts: 333
- Joined: Mon Nov 16, 2009 4:23 pm
- Location: Wales, United Kingdom
Re: saving paragraphs in multiline to mysql
for some reason I always forget that exists, don't know why...steven121 wrote:i used the nl2br function