Create post-HADVAs expect files
[hiphop-php.git] / hphp / test / zend / good / ext / standard / tests / file / fputcsv_variation7.php
blob3ab1202f08141c4892a40ce4504d6c21630982aa
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 /*
8 Testing fputcsv() to write to a file when enclosure is same but delimiter is different from those
9 present in the field to be written to the file
11 <<__EntryPoint>> function main(): void {
12 echo "*** Testing fputcsv() : with different delimiter and same enclosure ***\n";
14 /* the array is with three elements in it. Each element should be read as
15 1st element is delimiter, 2nd element is enclosure
16 and 3rd element is csv fields
18 $csv_lists = varray [
19 varray[',', '"', varray['water','fruit'] ],
20 varray[',', '"', varray['"water","fruit'] ],
21 varray[',', '"', varray['"water","fruit"'] ],
22 varray[' ', '^', varray['^water^ ^fruit^']],
23 varray[':', '&', varray['&water&:&fruit&']],
24 varray['=', '=', varray['=water===fruit=']],
25 varray['-', '-', varray['-water--fruit-air']],
26 varray['-', '-', varray['-water---fruit---air-']],
27 varray[':', '&', varray['&""""&:&"&:,:":&,&:,,,,']]
31 $filename = __SystemLib\hphp_test_tmppath('fputcsv_variation7.tmp');
33 $file_modes = varray ["r+", "r+b", "r+t",
34 "a+", "a+b", "a+t",
35 "w+", "w+b", "w+t",
36 "x+", "x+b", "x+t"];
38 $loop_counter = 1;
39 foreach ($csv_lists as $csv_list) {
40 for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
42 echo "\n-- file opened in $file_modes[$mode_counter] --\n";
43 // create the file and add the content with has csv fields
44 if ( strstr($file_modes[$mode_counter], "r") ) {
45 $file_handle = fopen($filename, "w");
46 } else {
47 $file_handle = fopen($filename, $file_modes[$mode_counter] );
49 if ( !$file_handle ) {
50 echo "Error: failed to create file $filename!\n";
51 exit();
53 $delimiter = $csv_list[0];
54 $enclosure = $csv_list[1];
55 $csv_field = $csv_list[2];
57 // write to a file in csv format
58 var_dump( fputcsv($file_handle, $csv_field, '+', $enclosure) );
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);
65 // print the file contents
66 var_dump( file_get_contents($filename) );
68 //delete file
69 unlink($filename);
70 } //end of mode loop
71 } // end of foreach
73 echo "Done\n";