473,395 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

removing linebreaks when inserting to mySQL?

I'm using a textarea to insert some notes into a database.
It's inserting the complete result into the mySQL table including the
linebreaks...and not as a visible symbol but an actual linebreak. If I
select the fireld in mySQL at a command prompt, the results take an
inordinate amount of space from all the linebreaks.

I tried nl2br() before it goes into the INSERT, but all that does is ADD <br
/> to the data but it still have linebreaks in the field.

Is there some way to replace linebreaks with something else than the break
itself so I can save database space?

Thanks!
Jul 17 '05 #1
5 2234
In article <ekWcc.207172$1p.2334423@attbi_s54>,
"Mechphisto" <li**@REEMOVEmechphisto.net> wrote:
Is there some way to replace linebreaks with something else than the break
itself so I can save database space?


You can of course do a str_replace to replace the linebreaks with
another character, but the data would take up just as much space as
before, so I'm not sure what the use would be?

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #2
"Jan Pieter Kunst" <de*****@cauce.org> wrote in message
news:de***************************@news1.news.xs4a ll.nl...
In article <ekWcc.207172$1p.2334423@attbi_s54>,
"Mechphisto" <li**@REEMOVEmechphisto.net> wrote:
Is there some way to replace linebreaks with something else than the break itself so I can save database space?
You can of course do a str_replace to replace the linebreaks with
another character, but the data would take up just as much space as
before, so I'm not sure what the use would be?


Isn't is taking up more space with the line breaks?
in mySQL if I type:select notes from table where id='#';

I get back:
+---------------------------------------------------------------------------
+
| First line
|
|Next line which may be longer.
|
|Another line that could be shorter but would take up as much room.
|
|So there appears to be a lot of empty space.
|
+---------------------------------------------------------------------------
+
Wouldn't it be better to have it more like:
+---------------------------------------------------------------------------
------+
| First line \n Next line which may be longer. \n |Another line that could
be shorter |
| but would take up as much room. \n So there appears to be a lot of empty
space.|
+---------------------------------------------------------------------------
------+
?
Thanks!
Jul 17 '05 #3
On Wed, 07 Apr 2004 17:32:53 +0000, Mechphisto wrote:
"Jan Pieter Kunst" <de*****@cauce.org> wrote in message
news:de***************************@news1.news.xs4a ll.nl...
In article <ekWcc.207172$1p.2334423@attbi_s54>,
"Mechphisto" <li**@REEMOVEmechphisto.net> wrote:
> Is there some way to replace linebreaks with something else than the break > itself so I can save database space?


You can of course do a str_replace to replace the linebreaks with
another character, but the data would take up just as much space as
before, so I'm not sure what the use would be?


Isn't is taking up more space with the line breaks?
in mySQL if I type:
select notes from table where id='#';

I get back:
+---------------------------------------------------------------------------
+
| First line
|
|Next line which may be longer.
|
|Another line that could be shorter but would take up as much room.
|
|So there appears to be a lot of empty space.
|
+---------------------------------------------------------------------------
+
Wouldn't it be better to have it more like:
+---------------------------------------------------------------------------
------+
| First line \n Next line which may be longer. \n |Another line that could
be shorter |
| but would take up as much room. \n So there appears to be a lot of empty
space.|
+---------------------------------------------------------------------------
------+
?
Thanks!


Can try addslashes().. which would then convert '\n' to '\\n' when the
insertion takes place, thus leaving you with '\n' in the actual DB field.
HTH =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #4
In article <9XWcc.212128$Cb.1820685@attbi_s51>,
"Mechphisto" <li**@REEMOVEmechphisto.net> wrote:
Isn't is taking up more space with the line breaks?
in mySQL if I type:
select notes from table where id='#';

I get back:
+---------------------------------------------------------------------------
+
| First line
|
|Next line which may be longer.
|
|Another line that could be shorter but would take up as much room.
|
|So there appears to be a lot of empty space.
|
+---------------------------------------------------------------------------
+
Wouldn't it be better to have it more like:
+---------------------------------------------------------------------------
------+
| First line \n Next line which may be longer. \n |Another line that could
be shorter |
| but would take up as much room. \n So there appears to be a lot of empty
space.|
+---------------------------------------------------------------------------
------+


Well, the first version takes up more visual space, but the second one
takes up more space in the database (one linebreak character vs. four
characters: space backslash n space).

It's up to you to decide what you want to do. Personally, I would just
leave the linebreaks as entered, and perhaps do a nl2br if I want to
show the text on a webpage.

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #5
"Jan Pieter Kunst" <de*****@cauce.org> wrote in message
news:de***************************@news1.news.xs4a ll.nl...
In article <9XWcc.212128$Cb.1820685@attbi_s51>,
"Mechphisto" <li**@REEMOVEmechphisto.net> wrote:
Isn't is taking up more space with the line breaks?
Well, the first version takes up more visual space, but the second one
takes up more space in the database (one linebreak character vs. four
characters: space backslash n space).


Visual only? All that space after a linebreak isn't actually IN the
database?
If that's the case, then I have no problem leaving as is. I was just afraid
that what I see is actually what's in the DB.
Thanks! =)
Liam
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Raqueeb Hassan | last post by:
Hello There! Have you guys tried inserting variables in mySQL tables? Do I have to use 'quote' as we had been doing to insert strings? mysql> INSERT INTO occurrence (word_id,page_id) VALUES...
7
by: Adam Honek | last post by:
Is there a direct way to remove one entry from a one dimensional array? I keep looking but either my eyes are funny or it isn't there. Must we really create a temp array and copy all but 1 of...
2
by: kokul_k | last post by:
Hi.. I'm facing a problem during inserting records in Mysql database. My table consists of 9 fields. When i try to insert 1000 records to this table using for loop it takes a lot of time.. nearly...
2
by: peter | last post by:
I have a xslt that writes a txt file from xml. Xml file is generated by a user input on a webpage and some nodes have linebreaks which corrupts my output. is there a way to generally set that xslt...
14
by: Ben | last post by:
I don't know whether anyone can help, but I have an odd problem. I have a PSP (Spyce) script that makes many calls to populate a database. They all work without any problem except for one...
5
by: rweth | last post by:
I am using nntplib to download archived xml messages from our internal newsgroup. This is working fine except the download of files to the connected server, has extra embedded lines in them (all...
0
by: Edwin.Madari | last post by:
-----Original Message----- statement prepared first and executed many times with exectemany - db API http://www.python.org/dev/peps/pep-0249/ inline statemets can be exeucuted only. hope that...
6
by: Bunty | last post by:
I want to insert values in the database.If i insert values one by one then it works till 4 or 5 fields then after it gives error.In my database there are more than 20 field.Pls help me.
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.