By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 949 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

New lines from php to mysql

P: n/a
Hi

I recently started to use nl2br() when displaying
text from a mysql database. This works as expected
but I am unsure how to prepare data before inserting
it to a table. How can I make sure that new line characters,
\n, are properly preserved with the data to be inserted?

thanks,
GH
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"George Hill" <ge********@europe.NOSPAM.com> wrote in message
news:bq**********@phys-news1.kolumbus.fi...
Hi

I recently started to use nl2br() when displaying
text from a mysql database. This works as expected
but I am unsure how to prepare data before inserting
it to a table. How can I make sure that new line characters,
\n, are properly preserved with the data to be inserted?

thanks,
GH

This is something alot of people go about the wrong way.
You should not alter the \n's when inserting, only when displaying to the
public.
Simply do this when displaying:
$text=ereg_replace("\n","<br>",$text);
echo $text;
Regards
Richard Grove

http://shopbuilder.org - ecommerce systems
Become a Shop Builder re-seller:
http://www.affiliatewindow.com/affil...ls.php?mid=611
http://www.affiliatewindow.com/a.pl?590

Jul 17 '05 #2

P: n/a
"George Hill" <ge********@europe.NOSPAM.com> schrieb:
I recently started to use nl2br() when displaying
text from a mysql database. This works as expected
but I am unsure how to prepare data before inserting
it to a table. How can I make sure that new line characters,
\n, are properly preserved with the data to be inserted?


They are preserved. Just add the data.

There's just one other thing: Make sure that you use the function
mysql_escape_string() before you add text to your MySQL database. This
will prevent MySQL from doing strange things if your text contains
quotes or double quotes.

Regards,
Matthias
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.