fgetcsv_variation26.phpt 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. --TEST--
  2. Test fgetcsv() : usage variations - reading files opened in write only mode (Bug #42036)
  3. --FILE--
  4. <?php
  5. /*
  6. Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] );
  7. Description: Gets line from file pointer and parse for CSV fields
  8. */
  9. /* Testing fgetcsv() to read from files opened in write only mode */
  10. echo "*** Testing fgetcsv() : reading the files opened in write only mode ***\n";
  11. /* the array is with three elements in it. Each element should be read as
  12. 1st element is delimiter, 2nd element is enclosure
  13. and 3rd element is csv fields
  14. */
  15. $csv_lists = array (
  16. array(',', '"', '"water",fruit'),
  17. array(',', '"', '"water","fruit"'),
  18. array(' ', '^', '^water^ ^fruit^'),
  19. array(':', '&', '&water&:&fruit&'),
  20. array('=', '=', '=water===fruit='),
  21. array('-', '-', '-water--fruit-air'),
  22. array('-', '-', '-water---fruit---air-'),
  23. array(':', '&', '&""""&:&"&:,:":&,&:,,,,')
  24. );
  25. $filename = dirname(__FILE__) . '/fgetcsv_variation26.tmp';
  26. @unlink($filename);
  27. $file_modes = array ("w", "wb", "wt",
  28. "a", "ab", "at",
  29. "x", "xb", "xt");
  30. $loop_counter = 1;
  31. foreach ($csv_lists as $csv_list) {
  32. for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
  33. // create the file and add the content with has csv fields
  34. $file_handle = fopen($filename, $file_modes[$mode_counter] );
  35. if ( !$file_handle ) {
  36. echo "Error: failed to create file $filename!\n";
  37. exit();
  38. }
  39. $delimiter = $csv_list[0];
  40. $enclosure = $csv_list[1];
  41. $csv_field = $csv_list[2];
  42. fwrite($file_handle, $csv_field . "\n");
  43. // write another line of text and a blank line
  44. // this will be used to test, if the fgetcsv() read more than a line and its
  45. // working when only a blank line is read
  46. fwrite($file_handle, "This is line of text without csv fields\n");
  47. fwrite($file_handle, "\n"); // blank line
  48. // rewind the file pointer to bof
  49. rewind($file_handle);
  50. echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n";
  51. // call fgetcsv() to parse csv fields
  52. // use the right delimiter and enclosure with max length
  53. var_dump( fgetcsv($file_handle, 1024, $delimiter, $enclosure) );
  54. // check the file pointer position and if eof
  55. var_dump( ftell($file_handle) );
  56. var_dump( feof($file_handle) );
  57. // close the file
  58. fclose($file_handle);
  59. //delete file
  60. unlink($filename);
  61. } //end of mode loop
  62. } // end of foreach
  63. echo "Done\n";
  64. ?>
  65. --EXPECT--
  66. *** Testing fgetcsv() : reading the files opened in write only mode ***
  67. -- Testing fgetcsv() with file opened using w mode --
  68. bool(false)
  69. int(0)
  70. bool(false)
  71. -- Testing fgetcsv() with file opened using wb mode --
  72. bool(false)
  73. int(0)
  74. bool(false)
  75. -- Testing fgetcsv() with file opened using wt mode --
  76. bool(false)
  77. int(0)
  78. bool(false)
  79. -- Testing fgetcsv() with file opened using a mode --
  80. bool(false)
  81. int(0)
  82. bool(false)
  83. -- Testing fgetcsv() with file opened using ab mode --
  84. bool(false)
  85. int(0)
  86. bool(false)
  87. -- Testing fgetcsv() with file opened using at mode --
  88. bool(false)
  89. int(0)
  90. bool(false)
  91. -- Testing fgetcsv() with file opened using x mode --
  92. bool(false)
  93. int(0)
  94. bool(false)
  95. -- Testing fgetcsv() with file opened using xb mode --
  96. bool(false)
  97. int(0)
  98. bool(false)
  99. -- Testing fgetcsv() with file opened using xt mode --
  100. bool(false)
  101. int(0)
  102. bool(false)
  103. -- Testing fgetcsv() with file opened using w mode --
  104. bool(false)
  105. int(0)
  106. bool(false)
  107. -- Testing fgetcsv() with file opened using wb mode --
  108. bool(false)
  109. int(0)
  110. bool(false)
  111. -- Testing fgetcsv() with file opened using wt mode --
  112. bool(false)
  113. int(0)
  114. bool(false)
  115. -- Testing fgetcsv() with file opened using a mode --
  116. bool(false)
  117. int(0)
  118. bool(false)
  119. -- Testing fgetcsv() with file opened using ab mode --
  120. bool(false)
  121. int(0)
  122. bool(false)
  123. -- Testing fgetcsv() with file opened using at mode --
  124. bool(false)
  125. int(0)
  126. bool(false)
  127. -- Testing fgetcsv() with file opened using x mode --
  128. bool(false)
  129. int(0)
  130. bool(false)
  131. -- Testing fgetcsv() with file opened using xb mode --
  132. bool(false)
  133. int(0)
  134. bool(false)
  135. -- Testing fgetcsv() with file opened using xt mode --
  136. bool(false)
  137. int(0)
  138. bool(false)
  139. -- Testing fgetcsv() with file opened using w mode --
  140. bool(false)
  141. int(0)
  142. bool(false)
  143. -- Testing fgetcsv() with file opened using wb mode --
  144. bool(false)
  145. int(0)
  146. bool(false)
  147. -- Testing fgetcsv() with file opened using wt mode --
  148. bool(false)
  149. int(0)
  150. bool(false)
  151. -- Testing fgetcsv() with file opened using a mode --
  152. bool(false)
  153. int(0)
  154. bool(false)
  155. -- Testing fgetcsv() with file opened using ab mode --
  156. bool(false)
  157. int(0)
  158. bool(false)
  159. -- Testing fgetcsv() with file opened using at mode --
  160. bool(false)
  161. int(0)
  162. bool(false)
  163. -- Testing fgetcsv() with file opened using x mode --
  164. bool(false)
  165. int(0)
  166. bool(false)
  167. -- Testing fgetcsv() with file opened using xb mode --
  168. bool(false)
  169. int(0)
  170. bool(false)
  171. -- Testing fgetcsv() with file opened using xt mode --
  172. bool(false)
  173. int(0)
  174. bool(false)
  175. -- Testing fgetcsv() with file opened using w mode --
  176. bool(false)
  177. int(0)
  178. bool(false)
  179. -- Testing fgetcsv() with file opened using wb mode --
  180. bool(false)
  181. int(0)
  182. bool(false)
  183. -- Testing fgetcsv() with file opened using wt mode --
  184. bool(false)
  185. int(0)
  186. bool(false)
  187. -- Testing fgetcsv() with file opened using a mode --
  188. bool(false)
  189. int(0)
  190. bool(false)
  191. -- Testing fgetcsv() with file opened using ab mode --
  192. bool(false)
  193. int(0)
  194. bool(false)
  195. -- Testing fgetcsv() with file opened using at mode --
  196. bool(false)
  197. int(0)
  198. bool(false)
  199. -- Testing fgetcsv() with file opened using x mode --
  200. bool(false)
  201. int(0)
  202. bool(false)
  203. -- Testing fgetcsv() with file opened using xb mode --
  204. bool(false)
  205. int(0)
  206. bool(false)
  207. -- Testing fgetcsv() with file opened using xt mode --
  208. bool(false)
  209. int(0)
  210. bool(false)
  211. -- Testing fgetcsv() with file opened using w mode --
  212. bool(false)
  213. int(0)
  214. bool(false)
  215. -- Testing fgetcsv() with file opened using wb mode --
  216. bool(false)
  217. int(0)
  218. bool(false)
  219. -- Testing fgetcsv() with file opened using wt mode --
  220. bool(false)
  221. int(0)
  222. bool(false)
  223. -- Testing fgetcsv() with file opened using a mode --
  224. bool(false)
  225. int(0)
  226. bool(false)
  227. -- Testing fgetcsv() with file opened using ab mode --
  228. bool(false)
  229. int(0)
  230. bool(false)
  231. -- Testing fgetcsv() with file opened using at mode --
  232. bool(false)
  233. int(0)
  234. bool(false)
  235. -- Testing fgetcsv() with file opened using x mode --
  236. bool(false)
  237. int(0)
  238. bool(false)
  239. -- Testing fgetcsv() with file opened using xb mode --
  240. bool(false)
  241. int(0)
  242. bool(false)
  243. -- Testing fgetcsv() with file opened using xt mode --
  244. bool(false)
  245. int(0)
  246. bool(false)
  247. -- Testing fgetcsv() with file opened using w mode --
  248. bool(false)
  249. int(0)
  250. bool(false)
  251. -- Testing fgetcsv() with file opened using wb mode --
  252. bool(false)
  253. int(0)
  254. bool(false)
  255. -- Testing fgetcsv() with file opened using wt mode --
  256. bool(false)
  257. int(0)
  258. bool(false)
  259. -- Testing fgetcsv() with file opened using a mode --
  260. bool(false)
  261. int(0)
  262. bool(false)
  263. -- Testing fgetcsv() with file opened using ab mode --
  264. bool(false)
  265. int(0)
  266. bool(false)
  267. -- Testing fgetcsv() with file opened using at mode --
  268. bool(false)
  269. int(0)
  270. bool(false)
  271. -- Testing fgetcsv() with file opened using x mode --
  272. bool(false)
  273. int(0)
  274. bool(false)
  275. -- Testing fgetcsv() with file opened using xb mode --
  276. bool(false)
  277. int(0)
  278. bool(false)
  279. -- Testing fgetcsv() with file opened using xt mode --
  280. bool(false)
  281. int(0)
  282. bool(false)
  283. -- Testing fgetcsv() with file opened using w mode --
  284. bool(false)
  285. int(0)
  286. bool(false)
  287. -- Testing fgetcsv() with file opened using wb mode --
  288. bool(false)
  289. int(0)
  290. bool(false)
  291. -- Testing fgetcsv() with file opened using wt mode --
  292. bool(false)
  293. int(0)
  294. bool(false)
  295. -- Testing fgetcsv() with file opened using a mode --
  296. bool(false)
  297. int(0)
  298. bool(false)
  299. -- Testing fgetcsv() with file opened using ab mode --
  300. bool(false)
  301. int(0)
  302. bool(false)
  303. -- Testing fgetcsv() with file opened using at mode --
  304. bool(false)
  305. int(0)
  306. bool(false)
  307. -- Testing fgetcsv() with file opened using x mode --
  308. bool(false)
  309. int(0)
  310. bool(false)
  311. -- Testing fgetcsv() with file opened using xb mode --
  312. bool(false)
  313. int(0)
  314. bool(false)
  315. -- Testing fgetcsv() with file opened using xt mode --
  316. bool(false)
  317. int(0)
  318. bool(false)
  319. -- Testing fgetcsv() with file opened using w mode --
  320. bool(false)
  321. int(0)
  322. bool(false)
  323. -- Testing fgetcsv() with file opened using wb mode --
  324. bool(false)
  325. int(0)
  326. bool(false)
  327. -- Testing fgetcsv() with file opened using wt mode --
  328. bool(false)
  329. int(0)
  330. bool(false)
  331. -- Testing fgetcsv() with file opened using a mode --
  332. bool(false)
  333. int(0)
  334. bool(false)
  335. -- Testing fgetcsv() with file opened using ab mode --
  336. bool(false)
  337. int(0)
  338. bool(false)
  339. -- Testing fgetcsv() with file opened using at mode --
  340. bool(false)
  341. int(0)
  342. bool(false)
  343. -- Testing fgetcsv() with file opened using x mode --
  344. bool(false)
  345. int(0)
  346. bool(false)
  347. -- Testing fgetcsv() with file opened using xb mode --
  348. bool(false)
  349. int(0)
  350. bool(false)
  351. -- Testing fgetcsv() with file opened using xt mode --
  352. bool(false)
  353. int(0)
  354. bool(false)
  355. Done