import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-file / fputcsv_variation13.php
blobfc6987c27a967ae30e4bfa9e269529043145eb6b
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 */
7 /* Testing fputcsv() to write to a file when default enclosure value and delimiter
8 of two chars is provided */
10 echo "*** Testing fputcsv() : with default enclosure & delimiter of two chars ***\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 = array (
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&')),
22 array('=', '=', array('=water===fruit=')),
23 array('-', '-', array('-water--fruit-air')),
24 array('-', '-', array('-water---fruit---air-')),
25 array(':', '&', array('&""""&:&"&:,:":&,&:,,,,'))
28 $file_path = dirname(__FILE__);
29 $filename = "$file_path/fputcsv_variation13.tmp";
31 $file_modes = array ("r+", "r+b", "r+t",
32 "a+", "a+b", "a+t",
33 "w+", "w+b", "w+t",
34 "x+", "x+b", "x+t");
36 $loop_counter = 1;
37 foreach ($csv_lists as $csv_list) {
38 for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
40 echo "\n-- file opened in $file_modes[$mode_counter] --\n";
41 // create the file and add the content with has csv fields
42 if ( strstr($file_modes[$mode_counter], "r") ) {
43 $file_handle = fopen($filename, "w");
44 } else {
45 $file_handle = fopen($filename, $file_modes[$mode_counter] );
47 if ( !$file_handle ) {
48 echo "Error: failed to create file $filename!\n";
49 exit();
51 $delimiter = $csv_list[0];
52 $enclosure = $csv_list[1];
53 $csv_field = $csv_list[2];
55 // write to a file in csv format
56 var_dump( fputcsv($file_handle, $csv_field, '++') );
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";