New lines from php to mysql

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

    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


  • Richard Grove

    #2
    Re: New lines from php to mysql

    "George Hill" <georgehill@eur ope.NOSPAM.com> wrote in message
    news:bqk3o9$j3g $1@phys-news1.kolumbus. fi...[color=blue]
    > 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
    >
    >[/color]


    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_repl ace("\n","<br>" ,$text);
    echo $text;


    Regards
    Richard Grove

    http://shopbuilder.org - ecommerce systems
    Become a Shop Builder re-seller:
    Affiliate marketing is a simple way to earn money online, using our affiliate platform. Join a global community of publishers and advertisers.

    Affiliate marketing is a simple way to earn money online, using our affiliate platform. Join a global community of publishers and advertisers.






    Comment

    • Matthias Esken

      #3
      Re: New lines from php to mysql

      "George Hill" <georgehill@eur ope.NOSPAM.com> schrieb:
      [color=blue]
      > 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?[/color]

      They are preserved. Just add the data.

      There's just one other thing: Make sure that you use the function
      mysql_escape_st ring() 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

      Comment

      Working...