Creating CSV and characters

Discussion in 'PHP' started by Triexa, May 2, 2007.

  1. #1
    If I am writing data to a file in a CSV format, how would I deal with characters such as newlines or quotes?

    Should I just addslashes() to each value, or should I do something else?

    Thanks in advance,

    Kaitlyn
     
    Triexa, May 2, 2007 IP
  2. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #2
    You should write them in the format
    item1,item2,item3\n\r
    PHP:
    from what I can remember. It's been a while since I wrote a script to output a CSV file so maybe I'm getting it wrong.
     
    Weirfire, May 3, 2007 IP
  3. Triexa

    Triexa Active Member

    Messages:
    580
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    I think I've determined the issue...

    New lines can in fact be in the CSV file... but the field shuold be quoted. And any quotes in a field should be double quoted (" turns into ""). Is anyone aware of any other "rules"?
     
    Triexa, May 3, 2007 IP