import zend standard tests
[hiphop-php.git] / hphp / test / zend / good / ext-standard-file / fputcsv_variation10.php
blobfd2f6f22de3ecbb7102ffc9f14f77cdba1caeac6
1 <?php
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 the field has no CSV format */
10 echo "*** Testing fputcsv() : with no CSV format in the field ***\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
17 $fields = array( array('water_fruit\n'),
18 array("water_fruit\n"),
19 array("")
22 $file_path = dirname(__FILE__);
23 $filename = "$file_path/fputcsv_variation10.tmp";
25 $file_modes = array ("r+", "r+b", "r+t",
26 "a+", "a+b", "a+t",
27 "w+", "w+b", "w+t",
28 "x+", "x+b", "x+t");
30 $loop_counter = 1;
31 foreach ($fields as $field) {
32 for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
34 echo "\n-- file opened in $file_modes[$mode_counter] --\n";
35 // create the file and add the content with has csv fields
36 if ( strstr($file_modes[$mode_counter], "r") ) {
37 $file_handle = fopen($filename, "w");
38 } else {
39 $file_handle = fopen($filename, $file_modes[$mode_counter] );
41 if ( !$file_handle ) {
42 echo "Error: failed to create file $filename!\n";
43 exit();
45 $csv_field = $field;
47 // write to a file in csv format
48 var_dump( fputcsv($file_handle, $csv_field) );
50 // check the file pointer position and eof
51 var_dump( ftell($file_handle) );
52 var_dump( feof($file_handle) );
53 //close the file
54 fclose($file_handle);
56 // print the file contents
57 var_dump( file_get_contents($filename) );
59 //delete file
60 unlink($filename);
61 } //end of mode loop
62 } // end of foreach
64 echo "Done\n";