fputcsv_variation11.phpt 12 KB

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