removing linebreaks when inserting to mySQL?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mechphisto

    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...an d 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!


  • Jan Pieter Kunst

    #2
    Re: removing linebreaks when inserting to mySQL?

    In article <ekWcc.207172$1 p.2334423@attbi _s54>,
    "Mechphisto " <liam@REEMOVEme chphisto.net> wrote:
    [color=blue]
    > Is there some way to replace linebreaks with something else than the break
    > itself so I can save database space?[/color]

    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, <devnull@cauce. org> is een "spam trap".
    E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.

    Comment

    • Mechphisto

      #3
      Re: removing linebreaks when inserting to mySQL?

      "Jan Pieter Kunst" <devnull@cauce. org> wrote in message
      news:devnull-ACD149.19151607 042004@news1.ne ws.xs4all.nl...[color=blue]
      > In article <ekWcc.207172$1 p.2334423@attbi _s54>,
      > "Mechphisto " <liam@REEMOVEme chphisto.net> wrote:
      >[color=green]
      > > Is there some way to replace linebreaks with something else than the[/color][/color]
      break[color=blue][color=green]
      > > itself so I can save database space?[/color]
      >
      > 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?[/color]

      Isn't is taking up more space with the line breaks?
      in mySQL if I type:[color=blue]
      >select notes from table where id='#';[/color]
      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!


      Comment

      • Ian.H

        #4
        Re: removing linebreaks when inserting to mySQL?

        On Wed, 07 Apr 2004 17:32:53 +0000, Mechphisto wrote:
        [color=blue]
        > "Jan Pieter Kunst" <devnull@cauce. org> wrote in message
        > news:devnull-ACD149.19151607 042004@news1.ne ws.xs4all.nl...[color=green]
        >> In article <ekWcc.207172$1 p.2334423@attbi _s54>,
        >> "Mechphisto " <liam@REEMOVEme chphisto.net> wrote:
        >>[color=darkred]
        >> > Is there some way to replace linebreaks with something else than the[/color][/color]
        > break[color=green][color=darkred]
        >> > itself so I can save database space?[/color]
        >>
        >> 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?[/color]
        >
        > Isn't is taking up more space with the line breaks?
        > in mySQL if I type:[color=green]
        >>select notes from table where id='#';[/color]
        > 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![/color]



        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


        Comment

        • Jan Pieter Kunst

          #5
          Re: removing linebreaks when inserting to mySQL?

          In article <9XWcc.212128$C b.1820685@attbi _s51>,
          "Mechphisto " <liam@REEMOVEme chphisto.net> wrote:
          [color=blue]
          > Isn't is taking up more space with the line breaks?
          > in mySQL if I type:[color=green]
          > >select notes from table where id='#';[/color]
          > 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.|
          > +---------------------------------------------------------------------------
          > ------+[/color]

          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, <devnull@cauce. org> is een "spam trap".
          E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.

          Comment

          • Mechphisto

            #6
            Re: removing linebreaks when inserting to mySQL?

            "Jan Pieter Kunst" <devnull@cauce. org> wrote in message
            news:devnull-BC0BFD.19591107 042004@news1.ne ws.xs4all.nl...[color=blue]
            > In article <9XWcc.212128$C b.1820685@attbi _s51>,
            > "Mechphisto " <liam@REEMOVEme chphisto.net> wrote:
            >[color=green]
            > > Isn't is taking up more space with the line breaks?[/color][/color]
            [color=blue]
            > 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).[/color]

            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


            Comment

            Working...