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

removing linebreaks when inserting to mySQL?

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.