fputcsv_variation13.phpt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. --TEST--
  2. Test fputcsv() : usage variations - with enclosure of two chars
  3. --FILE--
  4. <?php
  5. /* Testing fputcsv() to write to a file when default enclosure value and delimiter
  6. of two chars is provided */
  7. echo "*** Testing fputcsv() : with default enclosure & delimiter of two chars ***\n";
  8. /* the array is with three elements in it. Each element should be read as
  9. 1st element is delimiter, 2nd element is enclosure
  10. and 3rd element is csv fields
  11. */
  12. $csv_lists = array (
  13. array(',', '"', array('water,fruit') ),
  14. array(',', '"', array('"water","fruit') ),
  15. array(',', '"', array('"water","fruit"') ),
  16. array(' ', '^', array('^water^ ^fruit^')),
  17. array(':', '&', array('&water&:&fruit&')),
  18. array('=', '=', array('=water===fruit=')),
  19. array('-', '-', array('-water--fruit-air')),
  20. array('-', '-', array('-water---fruit---air-')),
  21. array(':', '&', array('&""""&:&"&:,:":&,&:,,,,'))
  22. );
  23. $file_path = __DIR__;
  24. $filename = "$file_path/fputcsv_variation13.tmp";
  25. $file_modes = array ("r+", "r+b", "r+t",
  26. "a+", "a+b", "a+t",
  27. "w+", "w+b", "w+t",
  28. "x+", "x+b", "x+t");
  29. $loop_counter = 1;
  30. foreach ($csv_lists as $csv_list) {
  31. for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
  32. echo "\n-- file opened in $file_modes[$mode_counter] --\n";
  33. // create the file and add the content with has csv fields
  34. if ( strstr($file_modes[$mode_counter], "r") ) {
  35. $file_handle = fopen($filename, "w");
  36. } else {
  37. $file_handle = fopen($filename, $file_modes[$mode_counter] );
  38. }
  39. if ( !$file_handle ) {
  40. echo "Error: failed to create file $filename!\n";
  41. exit();
  42. }
  43. $delimiter = $csv_list[0];
  44. $enclosure = $csv_list[1];
  45. $csv_field = $csv_list[2];
  46. // write to a file in csv format
  47. try {
  48. var_dump( fputcsv($file_handle, $csv_field, '+', '%%') );
  49. } catch (ValueError $e) {
  50. echo $e->getMessage(), "\n";
  51. }
  52. // check the file pointer position and eof
  53. var_dump( ftell($file_handle) );
  54. var_dump( feof($file_handle) );
  55. //close the file
  56. fclose($file_handle);
  57. // print the file contents
  58. var_dump( file_get_contents($filename) );
  59. //delete file
  60. unlink($filename);
  61. } //end of mode loop
  62. } // end of foreach
  63. echo "Done\n";
  64. ?>
  65. --EXPECT--
  66. *** Testing fputcsv() : with default enclosure & delimiter of two chars ***
  67. -- file opened in r+ --
  68. fputcsv(): Argument #4 ($enclosure) must be a single character
  69. int(0)
  70. bool(false)
  71. string(0) ""
  72. -- file opened in r+b --
  73. fputcsv(): Argument #4 ($enclosure) must be a single character
  74. int(0)
  75. bool(false)
  76. string(0) ""
  77. -- file opened in r+t --
  78. fputcsv(): Argument #4 ($enclosure) must be a single character
  79. int(0)
  80. bool(false)
  81. string(0) ""
  82. -- file opened in a+ --
  83. fputcsv(): Argument #4 ($enclosure) must be a single character
  84. int(0)
  85. bool(false)
  86. string(0) ""
  87. -- file opened in a+b --
  88. fputcsv(): Argument #4 ($enclosure) must be a single character
  89. int(0)
  90. bool(false)
  91. string(0) ""
  92. -- file opened in a+t --
  93. fputcsv(): Argument #4 ($enclosure) must be a single character
  94. int(0)
  95. bool(false)
  96. string(0) ""
  97. -- file opened in w+ --
  98. fputcsv(): Argument #4 ($enclosure) must be a single character
  99. int(0)
  100. bool(false)
  101. string(0) ""
  102. -- file opened in w+b --
  103. fputcsv(): Argument #4 ($enclosure) must be a single character
  104. int(0)
  105. bool(false)
  106. string(0) ""
  107. -- file opened in w+t --
  108. fputcsv(): Argument #4 ($enclosure) must be a single character
  109. int(0)
  110. bool(false)
  111. string(0) ""
  112. -- file opened in x+ --
  113. fputcsv(): Argument #4 ($enclosure) must be a single character
  114. int(0)
  115. bool(false)
  116. string(0) ""
  117. -- file opened in x+b --
  118. fputcsv(): Argument #4 ($enclosure) must be a single character
  119. int(0)
  120. bool(false)
  121. string(0) ""
  122. -- file opened in x+t --
  123. fputcsv(): Argument #4 ($enclosure) must be a single character
  124. int(0)
  125. bool(false)
  126. string(0) ""
  127. -- file opened in r+ --
  128. fputcsv(): Argument #4 ($enclosure) must be a single character
  129. int(0)
  130. bool(false)
  131. string(0) ""
  132. -- file opened in r+b --
  133. fputcsv(): Argument #4 ($enclosure) must be a single character
  134. int(0)
  135. bool(false)
  136. string(0) ""
  137. -- file opened in r+t --
  138. fputcsv(): Argument #4 ($enclosure) must be a single character
  139. int(0)
  140. bool(false)
  141. string(0) ""
  142. -- file opened in a+ --
  143. fputcsv(): Argument #4 ($enclosure) must be a single character
  144. int(0)
  145. bool(false)
  146. string(0) ""
  147. -- file opened in a+b --
  148. fputcsv(): Argument #4 ($enclosure) must be a single character
  149. int(0)
  150. bool(false)
  151. string(0) ""
  152. -- file opened in a+t --
  153. fputcsv(): Argument #4 ($enclosure) must be a single character
  154. int(0)
  155. bool(false)
  156. string(0) ""
  157. -- file opened in w+ --
  158. fputcsv(): Argument #4 ($enclosure) must be a single character
  159. int(0)
  160. bool(false)
  161. string(0) ""
  162. -- file opened in w+b --
  163. fputcsv(): Argument #4 ($enclosure) must be a single character
  164. int(0)
  165. bool(false)
  166. string(0) ""
  167. -- file opened in w+t --
  168. fputcsv(): Argument #4 ($enclosure) must be a single character
  169. int(0)
  170. bool(false)
  171. string(0) ""
  172. -- file opened in x+ --
  173. fputcsv(): Argument #4 ($enclosure) must be a single character
  174. int(0)
  175. bool(false)
  176. string(0) ""
  177. -- file opened in x+b --
  178. fputcsv(): Argument #4 ($enclosure) must be a single character
  179. int(0)
  180. bool(false)
  181. string(0) ""
  182. -- file opened in x+t --
  183. fputcsv(): Argument #4 ($enclosure) must be a single character
  184. int(0)
  185. bool(false)
  186. string(0) ""
  187. -- file opened in r+ --
  188. fputcsv(): Argument #4 ($enclosure) must be a single character
  189. int(0)
  190. bool(false)
  191. string(0) ""
  192. -- file opened in r+b --
  193. fputcsv(): Argument #4 ($enclosure) must be a single character
  194. int(0)
  195. bool(false)
  196. string(0) ""
  197. -- file opened in r+t --
  198. fputcsv(): Argument #4 ($enclosure) must be a single character
  199. int(0)
  200. bool(false)
  201. string(0) ""
  202. -- file opened in a+ --
  203. fputcsv(): Argument #4 ($enclosure) must be a single character
  204. int(0)
  205. bool(false)
  206. string(0) ""
  207. -- file opened in a+b --
  208. fputcsv(): Argument #4 ($enclosure) must be a single character
  209. int(0)
  210. bool(false)
  211. string(0) ""
  212. -- file opened in a+t --
  213. fputcsv(): Argument #4 ($enclosure) must be a single character
  214. int(0)
  215. bool(false)
  216. string(0) ""
  217. -- file opened in w+ --
  218. fputcsv(): Argument #4 ($enclosure) must be a single character
  219. int(0)
  220. bool(false)
  221. string(0) ""
  222. -- file opened in w+b --
  223. fputcsv(): Argument #4 ($enclosure) must be a single character
  224. int(0)
  225. bool(false)
  226. string(0) ""
  227. -- file opened in w+t --
  228. fputcsv(): Argument #4 ($enclosure) must be a single character
  229. int(0)
  230. bool(false)
  231. string(0) ""
  232. -- file opened in x+ --
  233. fputcsv(): Argument #4 ($enclosure) must be a single character
  234. int(0)
  235. bool(false)
  236. string(0) ""
  237. -- file opened in x+b --
  238. fputcsv(): Argument #4 ($enclosure) must be a single character
  239. int(0)
  240. bool(false)
  241. string(0) ""
  242. -- file opened in x+t --
  243. fputcsv(): Argument #4 ($enclosure) must be a single character
  244. int(0)
  245. bool(false)
  246. string(0) ""
  247. -- file opened in r+ --
  248. fputcsv(): Argument #4 ($enclosure) must be a single character
  249. int(0)
  250. bool(false)
  251. string(0) ""
  252. -- file opened in r+b --
  253. fputcsv(): Argument #4 ($enclosure) must be a single character
  254. int(0)
  255. bool(false)
  256. string(0) ""
  257. -- file opened in r+t --
  258. fputcsv(): Argument #4 ($enclosure) must be a single character
  259. int(0)
  260. bool(false)
  261. string(0) ""
  262. -- file opened in a+ --
  263. fputcsv(): Argument #4 ($enclosure) must be a single character
  264. int(0)
  265. bool(false)
  266. string(0) ""
  267. -- file opened in a+b --
  268. fputcsv(): Argument #4 ($enclosure) must be a single character
  269. int(0)
  270. bool(false)
  271. string(0) ""
  272. -- file opened in a+t --
  273. fputcsv(): Argument #4 ($enclosure) must be a single character
  274. int(0)
  275. bool(false)
  276. string(0) ""
  277. -- file opened in w+ --
  278. fputcsv(): Argument #4 ($enclosure) must be a single character
  279. int(0)
  280. bool(false)
  281. string(0) ""
  282. -- file opened in w+b --
  283. fputcsv(): Argument #4 ($enclosure) must be a single character
  284. int(0)
  285. bool(false)
  286. string(0) ""
  287. -- file opened in w+t --
  288. fputcsv(): Argument #4 ($enclosure) must be a single character
  289. int(0)
  290. bool(false)
  291. string(0) ""
  292. -- file opened in x+ --
  293. fputcsv(): Argument #4 ($enclosure) must be a single character
  294. int(0)
  295. bool(false)
  296. string(0) ""
  297. -- file opened in x+b --
  298. fputcsv(): Argument #4 ($enclosure) must be a single character
  299. int(0)
  300. bool(false)
  301. string(0) ""
  302. -- file opened in x+t --
  303. fputcsv(): Argument #4 ($enclosure) must be a single character
  304. int(0)
  305. bool(false)
  306. string(0) ""
  307. -- file opened in r+ --
  308. fputcsv(): Argument #4 ($enclosure) must be a single character
  309. int(0)
  310. bool(false)
  311. string(0) ""
  312. -- file opened in r+b --
  313. fputcsv(): Argument #4 ($enclosure) must be a single character
  314. int(0)
  315. bool(false)
  316. string(0) ""
  317. -- file opened in r+t --
  318. fputcsv(): Argument #4 ($enclosure) must be a single character
  319. int(0)
  320. bool(false)
  321. string(0) ""
  322. -- file opened in a+ --
  323. fputcsv(): Argument #4 ($enclosure) must be a single character
  324. int(0)
  325. bool(false)
  326. string(0) ""
  327. -- file opened in a+b --
  328. fputcsv(): Argument #4 ($enclosure) must be a single character
  329. int(0)
  330. bool(false)
  331. string(0) ""
  332. -- file opened in a+t --
  333. fputcsv(): Argument #4 ($enclosure) must be a single character
  334. int(0)
  335. bool(false)
  336. string(0) ""
  337. -- file opened in w+ --
  338. fputcsv(): Argument #4 ($enclosure) must be a single character
  339. int(0)
  340. bool(false)
  341. string(0) ""
  342. -- file opened in w+b --
  343. fputcsv(): Argument #4 ($enclosure) must be a single character
  344. int(0)
  345. bool(false)
  346. string(0) ""
  347. -- file opened in w+t --
  348. fputcsv(): Argument #4 ($enclosure) must be a single character
  349. int(0)
  350. bool(false)
  351. string(0) ""
  352. -- file opened in x+ --
  353. fputcsv(): Argument #4 ($enclosure) must be a single character
  354. int(0)
  355. bool(false)
  356. string(0) ""
  357. -- file opened in x+b --
  358. fputcsv(): Argument #4 ($enclosure) must be a single character
  359. int(0)
  360. bool(false)
  361. string(0) ""
  362. -- file opened in x+t --
  363. fputcsv(): Argument #4 ($enclosure) must be a single character
  364. int(0)
  365. bool(false)
  366. string(0) ""
  367. -- file opened in r+ --
  368. fputcsv(): Argument #4 ($enclosure) must be a single character
  369. int(0)
  370. bool(false)
  371. string(0) ""
  372. -- file opened in r+b --
  373. fputcsv(): Argument #4 ($enclosure) must be a single character
  374. int(0)
  375. bool(false)
  376. string(0) ""
  377. -- file opened in r+t --
  378. fputcsv(): Argument #4 ($enclosure) must be a single character
  379. int(0)
  380. bool(false)
  381. string(0) ""
  382. -- file opened in a+ --
  383. fputcsv(): Argument #4 ($enclosure) must be a single character
  384. int(0)
  385. bool(false)
  386. string(0) ""
  387. -- file opened in a+b --
  388. fputcsv(): Argument #4 ($enclosure) must be a single character
  389. int(0)
  390. bool(false)
  391. string(0) ""
  392. -- file opened in a+t --
  393. fputcsv(): Argument #4 ($enclosure) must be a single character
  394. int(0)
  395. bool(false)
  396. string(0) ""
  397. -- file opened in w+ --
  398. fputcsv(): Argument #4 ($enclosure) must be a single character
  399. int(0)
  400. bool(false)
  401. string(0) ""
  402. -- file opened in w+b --
  403. fputcsv(): Argument #4 ($enclosure) must be a single character
  404. int(0)
  405. bool(false)
  406. string(0) ""
  407. -- file opened in w+t --
  408. fputcsv(): Argument #4 ($enclosure) must be a single character
  409. int(0)
  410. bool(false)
  411. string(0) ""
  412. -- file opened in x+ --
  413. fputcsv(): Argument #4 ($enclosure) must be a single character
  414. int(0)
  415. bool(false)
  416. string(0) ""
  417. -- file opened in x+b --
  418. fputcsv(): Argument #4 ($enclosure) must be a single character
  419. int(0)
  420. bool(false)
  421. string(0) ""
  422. -- file opened in x+t --
  423. fputcsv(): Argument #4 ($enclosure) must be a single character
  424. int(0)
  425. bool(false)
  426. string(0) ""
  427. -- file opened in r+ --
  428. fputcsv(): Argument #4 ($enclosure) must be a single character
  429. int(0)
  430. bool(false)
  431. string(0) ""
  432. -- file opened in r+b --
  433. fputcsv(): Argument #4 ($enclosure) must be a single character
  434. int(0)
  435. bool(false)
  436. string(0) ""
  437. -- file opened in r+t --
  438. fputcsv(): Argument #4 ($enclosure) must be a single character
  439. int(0)
  440. bool(false)
  441. string(0) ""
  442. -- file opened in a+ --
  443. fputcsv(): Argument #4 ($enclosure) must be a single character
  444. int(0)
  445. bool(false)
  446. string(0) ""
  447. -- file opened in a+b --
  448. fputcsv(): Argument #4 ($enclosure) must be a single character
  449. int(0)
  450. bool(false)
  451. string(0) ""
  452. -- file opened in a+t --
  453. fputcsv(): Argument #4 ($enclosure) must be a single character
  454. int(0)
  455. bool(false)
  456. string(0) ""
  457. -- file opened in w+ --
  458. fputcsv(): Argument #4 ($enclosure) must be a single character
  459. int(0)
  460. bool(false)
  461. string(0) ""
  462. -- file opened in w+b --
  463. fputcsv(): Argument #4 ($enclosure) must be a single character
  464. int(0)
  465. bool(false)
  466. string(0) ""
  467. -- file opened in w+t --
  468. fputcsv(): Argument #4 ($enclosure) must be a single character
  469. int(0)
  470. bool(false)
  471. string(0) ""
  472. -- file opened in x+ --
  473. fputcsv(): Argument #4 ($enclosure) must be a single character
  474. int(0)
  475. bool(false)
  476. string(0) ""
  477. -- file opened in x+b --
  478. fputcsv(): Argument #4 ($enclosure) must be a single character
  479. int(0)
  480. bool(false)
  481. string(0) ""
  482. -- file opened in x+t --
  483. fputcsv(): Argument #4 ($enclosure) must be a single character
  484. int(0)
  485. bool(false)
  486. string(0) ""
  487. -- file opened in r+ --
  488. fputcsv(): Argument #4 ($enclosure) must be a single character
  489. int(0)
  490. bool(false)
  491. string(0) ""
  492. -- file opened in r+b --
  493. fputcsv(): Argument #4 ($enclosure) must be a single character
  494. int(0)
  495. bool(false)
  496. string(0) ""
  497. -- file opened in r+t --
  498. fputcsv(): Argument #4 ($enclosure) must be a single character
  499. int(0)
  500. bool(false)
  501. string(0) ""
  502. -- file opened in a+ --
  503. fputcsv(): Argument #4 ($enclosure) must be a single character
  504. int(0)
  505. bool(false)
  506. string(0) ""
  507. -- file opened in a+b --
  508. fputcsv(): Argument #4 ($enclosure) must be a single character
  509. int(0)
  510. bool(false)
  511. string(0) ""
  512. -- file opened in a+t --
  513. fputcsv(): Argument #4 ($enclosure) must be a single character
  514. int(0)
  515. bool(false)
  516. string(0) ""
  517. -- file opened in w+ --
  518. fputcsv(): Argument #4 ($enclosure) must be a single character
  519. int(0)
  520. bool(false)
  521. string(0) ""
  522. -- file opened in w+b --
  523. fputcsv(): Argument #4 ($enclosure) must be a single character
  524. int(0)
  525. bool(false)
  526. string(0) ""
  527. -- file opened in w+t --
  528. fputcsv(): Argument #4 ($enclosure) must be a single character
  529. int(0)
  530. bool(false)
  531. string(0) ""
  532. -- file opened in x+ --
  533. fputcsv(): Argument #4 ($enclosure) must be a single character
  534. int(0)
  535. bool(false)
  536. string(0) ""
  537. -- file opened in x+b --
  538. fputcsv(): Argument #4 ($enclosure) must be a single character
  539. int(0)
  540. bool(false)
  541. string(0) ""
  542. -- file opened in x+t --
  543. fputcsv(): Argument #4 ($enclosure) must be a single character
  544. int(0)
  545. bool(false)
  546. string(0) ""
  547. -- file opened in r+ --
  548. fputcsv(): Argument #4 ($enclosure) must be a single character
  549. int(0)
  550. bool(false)
  551. string(0) ""
  552. -- file opened in r+b --
  553. fputcsv(): Argument #4 ($enclosure) must be a single character
  554. int(0)
  555. bool(false)
  556. string(0) ""
  557. -- file opened in r+t --
  558. fputcsv(): Argument #4 ($enclosure) must be a single character
  559. int(0)
  560. bool(false)
  561. string(0) ""
  562. -- file opened in a+ --
  563. fputcsv(): Argument #4 ($enclosure) must be a single character
  564. int(0)
  565. bool(false)
  566. string(0) ""
  567. -- file opened in a+b --
  568. fputcsv(): Argument #4 ($enclosure) must be a single character
  569. int(0)
  570. bool(false)
  571. string(0) ""
  572. -- file opened in a+t --
  573. fputcsv(): Argument #4 ($enclosure) must be a single character
  574. int(0)
  575. bool(false)
  576. string(0) ""
  577. -- file opened in w+ --
  578. fputcsv(): Argument #4 ($enclosure) must be a single character
  579. int(0)
  580. bool(false)
  581. string(0) ""
  582. -- file opened in w+b --
  583. fputcsv(): Argument #4 ($enclosure) must be a single character
  584. int(0)
  585. bool(false)
  586. string(0) ""
  587. -- file opened in w+t --
  588. fputcsv(): Argument #4 ($enclosure) must be a single character
  589. int(0)
  590. bool(false)
  591. string(0) ""
  592. -- file opened in x+ --
  593. fputcsv(): Argument #4 ($enclosure) must be a single character
  594. int(0)
  595. bool(false)
  596. string(0) ""
  597. -- file opened in x+b --
  598. fputcsv(): Argument #4 ($enclosure) must be a single character
  599. int(0)
  600. bool(false)
  601. string(0) ""
  602. -- file opened in x+t --
  603. fputcsv(): Argument #4 ($enclosure) must be a single character
  604. int(0)
  605. bool(false)
  606. string(0) ""
  607. Done