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