SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Generate CSV files from form input - problem with line breaks in textareas

    Hello,

    I am trying to generate a CSV file from form input. Everything works fine, except that I can't get the line breaks in multi-line textarea input to look right when the CSV file is viewed in Excel.
    My guess is that I must replace the line break characters in the textarea input string with line break character recognized by Excel, probably using str_replace. The problem is that I don't know for what characters to look and with what to replace. Hope someone can help. Thanks!

    Marius

  2. #2
    SitePoint Zealot
    Join Date
    Sep 2007
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    leave line breaks the way they are \n

    it should work fine

    I just opened excel, wailed on my keyboard with some linebreaks and stuff

    Code:
    "luy
    ghtrehtser",htrea,56436,hter ht rsh
    65365 4 ,tsrjyrjyfj ytj sy,htrs h,htsh 
    htrd 5y54w yh,,"kut djkyut 
    hterhs89ht",nhtrsjtrs
    nyrmjyrs,yrjsy,sjyrsjyrsngf ntr ,hjsr tysr j
    looks fine in excel

  3. #3
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Of course line breaks entered in Excel look fine in Excel, my line breaks are entered from a textarea input, and appear in Excel as an unknown character.
    Thanks anyway!

    Marus

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you try to replace '\n' or something chr(13) with the ascii value?
    PHP Code:
    $text str_replace('\n'"",$text); 
    I think if you need that '\n' in the out when you get it from CSV, you can replace with some spacial character or phrase so that you can again replace it when you want to output in the screen later on.
    PHP Code:
    $text str_replace('\n'"[n]"$text);
    # and you can replace [n] with <br> later on in your output.
    $text str_replace("[n]""<br />"$text); 
    I am not sure if there are any special functions to do so.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP function nl2br could help here? Later you could replace '<br />' back to '\n' if you wanted...
    Cheers!
    Sumit
    OnJobs.org


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •