fputcsv_variation17.phpt 742 B

12345678910111213141516171819202122232425262728293031
  1. --TEST--
  2. fputcsv() with user provided eol
  3. --FILE--
  4. <?php
  5. $data = [
  6. ['aaa', 'bbb', 'ccc', 'dddd'],
  7. ['123', '456', '789'],
  8. ['"aaa"', '"bbb"'],
  9. ];
  10. $eol_chars = ['||', '|', '\n', "\n", "\0"];
  11. foreach ($eol_chars as $eol_char) {
  12. $stream = fopen('php://memory', 'w+');
  13. foreach ($data as $record) {
  14. fputcsv($stream, $record, ',', '"', '\\', $eol_char);
  15. }
  16. rewind($stream);
  17. echo stream_get_contents($stream), "\n";
  18. fclose($stream);
  19. }
  20. ?>
  21. --EXPECTF--
  22. aaa,bbb,ccc,dddd||123,456,789||"""aaa""","""bbb"""||
  23. aaa,bbb,ccc,dddd|123,456,789|"""aaa""","""bbb"""|
  24. aaa,bbb,ccc,dddd\n123,456,789\n"""aaa""","""bbb"""\n
  25. aaa,bbb,ccc,dddd
  26. 123,456,789
  27. """aaa""","""bbb"""
  28. aaa,bbb,ccc,dddd%0123,456,789%0"""aaa""","""bbb"""