fputcsv_variation15.phpt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. --TEST--
  2. various fputcsv() functionality tests
  3. --CREDITS--
  4. Lee Leathers <leeleathers@gmail.com>
  5. --FILE--
  6. <?php
  7. $list = array (
  8. 0 => 'aaa,bbb',
  9. 1 => 'aaa,"bbb"',
  10. 2 => '"aaa","bbb"',
  11. 3 => 'aaa,bbb',
  12. 4 => '"aaa",bbb',
  13. 5 => '"aaa", "bbb"',
  14. 6 => ',',
  15. 7 => 'aaa,',
  16. 8 => ',"aaa"',
  17. 9 => '"",""',
  18. 10 => '"""""",',
  19. 11 => '""""",aaa',
  20. 12 => 'aaa,bbb ',
  21. 13 => 'aaa,"bbb "',
  22. 14 => 'aaa"aaa","bbb"bbb',
  23. 15 => 'aaa"aaa""",bbb',
  24. 16 => 'aaa,"/"bbb,ccc',
  25. 17 => 'aaa"/"a","bbb"',
  26. 18 => '"/"","aaa"',
  27. 19 => '"/""",aaa',
  28. );
  29. $file = __DIR__ . '/fputcsv_variation15.csv';
  30. @unlink($file);
  31. $fp = fopen($file, "w");
  32. foreach ($list as $v) {
  33. fputcsv($fp, explode(',', $v), ',', '"', '/');
  34. }
  35. fclose($fp);
  36. $res = file($file);
  37. foreach($res as &$val)
  38. {
  39. $val = substr($val, 0, -1);
  40. }
  41. echo '$list = ';var_export($res);echo ";\n";
  42. $fp = fopen($file, "r");
  43. $res = array();
  44. while($l=fgetcsv($fp, 0, ',', '"', '/'))
  45. {
  46. $res[] = join(',',$l);
  47. }
  48. fclose($fp);
  49. echo '$list = ';var_export($res);echo ";\n";
  50. @unlink($file);
  51. ?>
  52. --EXPECT--
  53. $list = array (
  54. 0 => 'aaa,bbb',
  55. 1 => 'aaa,"""bbb"""',
  56. 2 => '"""aaa""","""bbb"""',
  57. 3 => 'aaa,bbb',
  58. 4 => '"""aaa""",bbb',
  59. 5 => '"""aaa"""," ""bbb"""',
  60. 6 => ',',
  61. 7 => 'aaa,',
  62. 8 => ',"""aaa"""',
  63. 9 => '"""""",""""""',
  64. 10 => '"""""""""""""",',
  65. 11 => '"""""""""""",aaa',
  66. 12 => 'aaa,"bbb "',
  67. 13 => 'aaa,"""bbb """',
  68. 14 => '"aaa""aaa""","""bbb""bbb"',
  69. 15 => '"aaa""aaa""""""",bbb',
  70. 16 => 'aaa,"""/"bbb",ccc',
  71. 17 => '"aaa""/"a""","""bbb"""',
  72. 18 => '"""/"""","""aaa"""',
  73. 19 => '"""/"""""",aaa',
  74. );
  75. $list = array (
  76. 0 => 'aaa,bbb',
  77. 1 => 'aaa,"bbb"',
  78. 2 => '"aaa","bbb"',
  79. 3 => 'aaa,bbb',
  80. 4 => '"aaa",bbb',
  81. 5 => '"aaa", "bbb"',
  82. 6 => ',',
  83. 7 => 'aaa,',
  84. 8 => ',"aaa"',
  85. 9 => '"",""',
  86. 10 => '"""""",',
  87. 11 => '""""",aaa',
  88. 12 => 'aaa,bbb ',
  89. 13 => 'aaa,"bbb "',
  90. 14 => 'aaa"aaa","bbb"bbb',
  91. 15 => 'aaa"aaa""",bbb',
  92. 16 => 'aaa,"/"bbb,ccc',
  93. 17 => 'aaa"/"a","bbb"',
  94. 18 => '"/"","aaa"',
  95. 19 => '"/""",aaa',
  96. );