title: fputcsv and newline codes
body: <p>I'm using fputcsv in PHP to output a comma-delimited file of a database query. When opening the file in gedit in Ubuntu, it looks correct - each record has a line break (no visible line break characters, but you can tell each record is separated,and opening it in OpenOffice spreadsheet allows me to view the file correctly.)</p>
  
  <p>However, we're sending these files on to a client on Windows, and on their systems, the file comes in as one big, long line. Opening it in Excel, it doesn't recognize multiple lines at all.</p>
  
  <p>I've read several questions on here that are pretty similar, including <a href="https://stackoverflow.com/questions/2378268/fputcsv-and-notepad">this one</a>, which includes a link to the really informative <a href="http://www.codinghorror.com/blog/2010/01/the-great-newline-schism.html" rel="noreferrer">Great Newline Schism</a> explanation.</p>
  
  <p>Unfortunately, we can't just tell our clients to open the files in a "smarter" editor. They need to be able to open them in Excel. Is there any programmatic way to ensure that the correct newline characters are added so the file can be opened in a spreadsheet program on any OS?</p>
  
  <p>I'm already using a custom function to force quotes around all values, since fputcsv is selective about it. I've tried doing something like this:</p>
  
  <pre><code>function my_fputcsv($handle, $fieldsarray, $delimiter = "~", $enclosure ='"'){
  
          $glue = $enclosure . $delimiter . $enclosure;
  
      return fwrite($handle, $enclosure . implode($glue,$fieldsarray) . $enclosure."\r\n");
  
  }
  </code></pre>
  
  <p>But when the file is opened in a Windows text editor, it still shows up as a single long line.</p>