Create post-HADVAs expect files
[hiphop-php.git] / hphp / test / zend / good / ext / standard / tests / file / fputcsv_variation2.php
blob072d741a954f938d55fce8510ff562c6107594a7
1 <?hh
2 /*
3 Prototype: array fputcsv ( resource $handle , array $fields [, string $delimiter [, string $enclosure]]] );
4 Description: Format line as CSV and write to the file pointer
5 */
7 /* Testing fputcsv() to write to a file when delimiter is NULL */
8 <<__EntryPoint>> function main(): void {
9 echo "*** Testing fputcsv() : with delimiter as NULL ***\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
15 $csv_lists = varray [
16 varray[',', '"', varray['water','fruit'] ],
17 varray[',', '"', varray['"water","fruit'] ],
18 varray[',', '"', varray['"water","fruit"'] ],
19 varray[' ', '^', varray['^water^ ^fruit^']],
20 varray[':', '&', varray['&water&:&fruit&']],
21 varray['=', '=', varray['=water===fruit=']],
22 varray['-', '-', varray['-water--fruit-air']],
23 varray['-', '-', varray['-water---fruit---air-']],
24 varray[':', '&', varray['&""""&:&"&:,:":&,&:,,,,']]
28 $filename = __SystemLib\hphp_test_tmppath('fputcsv_variation2.tmp');
30 $file_modes = varray ["r+", "r+b", "r+t",
31 "a+", "a+b", "a+t",
32 "w+", "w+b", "w+t",
33 "x+", "x+b", "x+t"];
35 $loop_counter = 1;
36 foreach ($csv_lists as $csv_list) {
37 for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
39 echo "\n-- file opened in $file_modes[$mode_counter] --\n";
40 // create the file and add the content with has csv fields
41 if ( strstr($file_modes[$mode_counter], "r") ) {
42 $file_handle = fopen($filename, "w");
43 } else {
44 $file_handle = fopen($filename, $file_modes[$mode_counter] );
46 if ( !$file_handle ) {
47 echo "Error: failed to create file $filename!\n";
48 exit();
50 $delimiter = $csv_list[0];
51 $enclosure = $csv_list[1];
52 $csv_field = $csv_list[2];
54 // write to a file in csv format
55 var_dump( fputcsv($file_handle, $csv_field, '', $enclosure) );
56 // check the file pointer position and eof
57 var_dump( ftell($file_handle) );
58 var_dump( feof($file_handle) );
59 //close the file
60 fclose($file_handle);
62 // print the file contents
63 var_dump( file_get_contents($filename) );
65 //delete file
66 unlink($filename);
67 } //end of mode loop
68 } // end of foreach
70 echo "Done\n";