473,472 Members | 2,224 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

New lines from php to mysql

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
2 2569
"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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: deko | last post by:
I'm not sure how to do this in php - need to calculate and delete an unspecified number of lines from the *top* of a file. <?php //append $visitor to the bottom of $visdata $fp =...
11
by: QS Computing | last post by:
Hi, I'm trying to write a simple forum script and I want to include '>' at the start of lines in quoted text (like on USENET). How do I go about doing this? My post is stored in a MySQL DB text...
1
by: Asteras | last post by:
Hi All!!! Let us consider two tables in a MySQL database: 1) C_T is a table of school classes and the teachers that teach in them: select * from C_T; +-------+---------+
2
by: Lakigam | last post by:
Hello - I have 2 identical tables in the same MySQL database - I want to copy some content of the first one to the second one Any idea how to do this without using INSERT the DELETE ??? ...
3
by: Ja NE | last post by:
well, it is time for some fine tuning of my application, after adding that banner script for which I needed percentage solution, I would like to fix my forum scripts... when someone write some...
2
by: Baxter337 | last post by:
I am trying to pass a php variable that i get from a mysql text field to a javascript function, but that text field has newlines in it. <a href="#top"...
2
by: medaps | last post by:
Hi, How do I save multi lines to a mysql memo field replacing char 13 char 10 to '\r\n' instead ?. Example the memo is saved as 'string1<13><10>string2' instead of 'string1\r\nstring2' The...
5
pezholio
by: pezholio | last post by:
Hi, I've got an inline list with a label and checkbox in each list item, each item comes from a MySQL database and, chances are that, in future, the list will become longer. My problem is that...
2
by: pavanponnapalli | last post by:
hi, I have got a batch file where i have written the following modules from CPAN: ppm install DBI ppm install DBD::mysql ppm install Config::Properties ppm install Net::SMTP ppm...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.