1--TEST-- 2SplFileObject::fputcsv(): Usage variations -- with line without any CSV fields 3--FILE-- 4<?php 5 6/* Testing fputcsv() to write to a file when the field has no CSV format */ 7 8echo "*** Testing fputcsv() : with no CSV format in the field ***\n"; 9 10/* the array is with three elements in it. Each element should be read as 11 1st element is delimiter, 2nd element is enclosure 12 and 3rd element is csv fields 13*/ 14 15$fields = array( array('water_fruit\n'), 16 array("water_fruit\n"), 17 array("") 18 ); 19 20$file_path = dirname(__FILE__); 21$file = "$file_path/fputcsv_variation10.tmp"; 22 23$file_modes = array ("r+", "r+b", "r+t", 24 "a+", "a+b", "a+t", 25 "w+", "w+b", "w+t", 26 "x+", "x+b", "x+t"); 27 28$loop_counter = 1; 29foreach ($fields as $field) { 30 for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { 31 32 echo "\n-- file opened in $file_modes[$mode_counter] --\n"; 33 // create the file and add the content with has csv fields 34 if ( strstr($file_modes[$mode_counter], "r") ) { 35 $fo = new SplFileObject($file, 'w'); 36 } else { 37 $fo = new SplFileObject($file, $file_modes[$mode_counter]); 38 } 39 $csv_field = $field; 40 41 // write to a file in csv format 42 var_dump( $fo->fputcsv($csv_field) ); 43 44 // check the file pointer position and eof 45 var_dump( $fo->ftell() ); 46 var_dump( $fo->eof() ); 47 //close the file 48 unset($fo); 49 50 // print the file contents 51 var_dump( file_get_contents($file) ); 52 53 //delete file 54 unlink($file); 55 } //end of mode loop 56} // end of foreach 57 58echo "Done\n"; 59?> 60--EXPECTF-- 61*** Testing fputcsv() : with no CSV format in the field *** 62 63-- file opened in r+ -- 64int(16) 65int(16) 66bool(false) 67string(16) ""water_fruit\n" 68" 69 70-- file opened in r+b -- 71int(16) 72int(16) 73bool(false) 74string(16) ""water_fruit\n" 75" 76 77-- file opened in r+t -- 78int(16) 79int(16) 80bool(false) 81string(%d) ""water_fruit\n" 82" 83 84-- file opened in a+ -- 85int(16) 86int(16) 87bool(false) 88string(16) ""water_fruit\n" 89" 90 91-- file opened in a+b -- 92int(16) 93int(16) 94bool(false) 95string(16) ""water_fruit\n" 96" 97 98-- file opened in a+t -- 99int(16) 100int(16) 101bool(false) 102string(%d) ""water_fruit\n" 103" 104 105-- file opened in w+ -- 106int(16) 107int(16) 108bool(false) 109string(16) ""water_fruit\n" 110" 111 112-- file opened in w+b -- 113int(16) 114int(16) 115bool(false) 116string(16) ""water_fruit\n" 117" 118 119-- file opened in w+t -- 120int(16) 121int(16) 122bool(false) 123string(%d) ""water_fruit\n" 124" 125 126-- file opened in x+ -- 127int(16) 128int(16) 129bool(false) 130string(16) ""water_fruit\n" 131" 132 133-- file opened in x+b -- 134int(16) 135int(16) 136bool(false) 137string(16) ""water_fruit\n" 138" 139 140-- file opened in x+t -- 141int(16) 142int(16) 143bool(false) 144string(%d) ""water_fruit\n" 145" 146 147-- file opened in r+ -- 148int(15) 149int(15) 150bool(false) 151string(15) ""water_fruit 152" 153" 154 155-- file opened in r+b -- 156int(15) 157int(15) 158bool(false) 159string(15) ""water_fruit 160" 161" 162 163-- file opened in r+t -- 164int(15) 165int(15) 166bool(false) 167string(%d) ""water_fruit 168" 169" 170 171-- file opened in a+ -- 172int(15) 173int(15) 174bool(false) 175string(15) ""water_fruit 176" 177" 178 179-- file opened in a+b -- 180int(15) 181int(15) 182bool(false) 183string(15) ""water_fruit 184" 185" 186 187-- file opened in a+t -- 188int(15) 189int(15) 190bool(false) 191string(%d) ""water_fruit 192" 193" 194 195-- file opened in w+ -- 196int(15) 197int(15) 198bool(false) 199string(15) ""water_fruit 200" 201" 202 203-- file opened in w+b -- 204int(15) 205int(15) 206bool(false) 207string(15) ""water_fruit 208" 209" 210 211-- file opened in w+t -- 212int(15) 213int(15) 214bool(false) 215string(%d) ""water_fruit 216" 217" 218 219-- file opened in x+ -- 220int(15) 221int(15) 222bool(false) 223string(15) ""water_fruit 224" 225" 226 227-- file opened in x+b -- 228int(15) 229int(15) 230bool(false) 231string(15) ""water_fruit 232" 233" 234 235-- file opened in x+t -- 236int(15) 237int(15) 238bool(false) 239string(%d) ""water_fruit 240" 241" 242 243-- file opened in r+ -- 244int(1) 245int(1) 246bool(false) 247string(1) " 248" 249 250-- file opened in r+b -- 251int(1) 252int(1) 253bool(false) 254string(1) " 255" 256 257-- file opened in r+t -- 258int(1) 259int(1) 260bool(false) 261string(%d) " 262" 263 264-- file opened in a+ -- 265int(1) 266int(1) 267bool(false) 268string(1) " 269" 270 271-- file opened in a+b -- 272int(1) 273int(1) 274bool(false) 275string(1) " 276" 277 278-- file opened in a+t -- 279int(1) 280int(1) 281bool(false) 282string(%d) " 283" 284 285-- file opened in w+ -- 286int(1) 287int(1) 288bool(false) 289string(1) " 290" 291 292-- file opened in w+b -- 293int(1) 294int(1) 295bool(false) 296string(1) " 297" 298 299-- file opened in w+t -- 300int(1) 301int(1) 302bool(false) 303string(%d) " 304" 305 306-- file opened in x+ -- 307int(1) 308int(1) 309bool(false) 310string(1) " 311" 312 313-- file opened in x+b -- 314int(1) 315int(1) 316bool(false) 317string(1) " 318" 319 320-- file opened in x+t -- 321int(1) 322int(1) 323bool(false) 324string(%d) " 325" 326Done 327