Create post-HADVAs expect files
[hiphop-php.git] / hphp / test / zend / good / ext / standard / tests / file / fputcsv_variation9.php
blob33551b3bf3788ccd22f0e7b50eb93fc5f65a847c
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 */
8 /* Testing fputcsv() to write to a file when delimiter and enclosure are of two chars each */
9 <<__EntryPoint>> function main(): void {
10 echo "*** Testing fputcsv() : with two chars as enclosure & delimiter ***\n";
12 /* the array is with three elements in it. Each element should be read as
13 1st element is delimiter, 2nd element is enclosure
14 and 3rd element is csv fields
16 $csv_lists = varray [
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=']],
23 varray['-', '-', varray['-water--fruit-air']],
24 varray['-', '-', varray['-water---fruit---air-']],
25 varray[':', '&', varray['&""""&:&"&:,:":&,&:,,,,']]
28 $filename = __SystemLib\hphp_test_tmppath('fputcsv_variation9.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, '++', '%%'
56 ) );
57 // check the file pointer position and eof
58 var_dump( ftell($file_handle) );
59 var_dump( feof($file_handle) );
60 //close the file
61 fclose($file_handle);
63 // print the file contents
64 var_dump( file_get_contents($filename) );
66 //delete file
67 unlink($filename);
68 } //end of mode loop
69 } // end of foreach
71 echo "Done\n";