fgetcsv.phpt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. --TEST--
  2. various fgetcsv() functionality tests
  3. --FILE--
  4. <?php
  5. $list = array(
  6. 'aaa,bbb',
  7. 'aaa,"bbb"',
  8. '"aaa","bbb"',
  9. 'aaa,bbb',
  10. '"aaa",bbb',
  11. '"aaa", "bbb"',
  12. ',',
  13. 'aaa,',
  14. ',"aaa"',
  15. '"",""',
  16. '"\\"","aaa"',
  17. '"""""",',
  18. '""""",aaa' . "\n",
  19. '"\\""",aaa' . "\n",
  20. 'aaa,"\\"bbb,ccc' . "\n",
  21. 'aaa,bbb ',
  22. 'aaa,"bbb "',
  23. 'aaa"aaa","bbb"bbb',
  24. 'aaa"aaa""",bbb',
  25. 'aaa"\\"a","bbb"',
  26. 'aaa,"bbb' . "\n",
  27. 'aaa,"bbb',
  28. );
  29. $file = __DIR__ . '/fgetcsv.csv';
  30. @unlink($file);
  31. foreach ($list as $v) {
  32. $fp = fopen($file, "w");
  33. fwrite($fp, $v);
  34. fclose($fp);
  35. var_dump(fgetcsv(fopen($file, "r"), 1024));
  36. }
  37. @unlink($file);
  38. ?>
  39. --EXPECT--
  40. array(2) {
  41. [0]=>
  42. string(3) "aaa"
  43. [1]=>
  44. string(3) "bbb"
  45. }
  46. array(2) {
  47. [0]=>
  48. string(3) "aaa"
  49. [1]=>
  50. string(3) "bbb"
  51. }
  52. array(2) {
  53. [0]=>
  54. string(3) "aaa"
  55. [1]=>
  56. string(3) "bbb"
  57. }
  58. array(2) {
  59. [0]=>
  60. string(3) "aaa"
  61. [1]=>
  62. string(3) "bbb"
  63. }
  64. array(2) {
  65. [0]=>
  66. string(3) "aaa"
  67. [1]=>
  68. string(3) "bbb"
  69. }
  70. array(2) {
  71. [0]=>
  72. string(3) "aaa"
  73. [1]=>
  74. string(3) "bbb"
  75. }
  76. array(2) {
  77. [0]=>
  78. string(0) ""
  79. [1]=>
  80. string(0) ""
  81. }
  82. array(2) {
  83. [0]=>
  84. string(3) "aaa"
  85. [1]=>
  86. string(0) ""
  87. }
  88. array(2) {
  89. [0]=>
  90. string(0) ""
  91. [1]=>
  92. string(3) "aaa"
  93. }
  94. array(2) {
  95. [0]=>
  96. string(0) ""
  97. [1]=>
  98. string(0) ""
  99. }
  100. array(2) {
  101. [0]=>
  102. string(2) "\""
  103. [1]=>
  104. string(3) "aaa"
  105. }
  106. array(2) {
  107. [0]=>
  108. string(2) """"
  109. [1]=>
  110. string(0) ""
  111. }
  112. array(1) {
  113. [0]=>
  114. string(7) """,aaa
  115. "
  116. }
  117. array(1) {
  118. [0]=>
  119. string(8) "\"",aaa
  120. "
  121. }
  122. array(2) {
  123. [0]=>
  124. string(3) "aaa"
  125. [1]=>
  126. string(10) "\"bbb,ccc
  127. "
  128. }
  129. array(2) {
  130. [0]=>
  131. string(3) "aaa"
  132. [1]=>
  133. string(6) "bbb "
  134. }
  135. array(2) {
  136. [0]=>
  137. string(3) "aaa"
  138. [1]=>
  139. string(6) "bbb "
  140. }
  141. array(2) {
  142. [0]=>
  143. string(8) "aaa"aaa""
  144. [1]=>
  145. string(6) "bbbbbb"
  146. }
  147. array(2) {
  148. [0]=>
  149. string(10) "aaa"aaa""""
  150. [1]=>
  151. string(3) "bbb"
  152. }
  153. array(2) {
  154. [0]=>
  155. string(8) "aaa"\"a""
  156. [1]=>
  157. string(3) "bbb"
  158. }
  159. array(2) {
  160. [0]=>
  161. string(3) "aaa"
  162. [1]=>
  163. string(4) "bbb
  164. "
  165. }
  166. array(2) {
  167. [0]=>
  168. string(3) "aaa"
  169. [1]=>
  170. string(3) "bbb"
  171. }