1--TEST-- 2Test fgetcsv() : usage variations - with line without any csv fields 3--FILE-- 4<?php 5/* Testing fgetcsv() to read a line from a file which doesn't have any CSV field */ 6 7echo "*** Testing fgetcsv() : reading the line which is without csv fields ***\n"; 8 9 10$filename = __DIR__ . '/fgetcsv_variation13.tmp'; 11@unlink($filename); 12 13$file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t", 14 "a+", "a+b", "a+t", 15 "w+", "w+b", "w+t", 16 "x+", "x+b", "x+t"); 17 18$loop_counter = 1; 19 for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { 20 // create the file and add the content with has csv fields 21 if ( strstr($file_modes[$mode_counter], "r") ) { 22 $file_handle = fopen($filename, "w"); 23 } else { 24 $file_handle = fopen($filename, $file_modes[$mode_counter] ); 25 } 26 if ( !$file_handle ) { 27 echo "Error: failed to create file $filename!\n"; 28 exit(); 29 } 30 // write line of text 31 fwrite($file_handle, "This is line of text without csv fields\n"); 32 33 // close the file if the mode to be used is read mode and re-open using read mode 34 // else rewind the file pointer to beginning of the file 35 if ( strstr($file_modes[$mode_counter], "r" ) ) { 36 fclose($file_handle); 37 $file_handle = fopen($filename, $file_modes[$mode_counter]); 38 } else { 39 // rewind the file pointer to bof 40 rewind($file_handle); 41 } 42 43 echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; 44 45 46 // read the line which is without csv fields, provide delimiter and see the working of fgetcsv 47 $fp_pos = ftell($file_handle); 48 var_dump( fgetcsv($file_handle, escape: "\\") ); 49 // check the file pointer position and if eof 50 var_dump( ftell($file_handle) ); 51 var_dump( feof($file_handle) ); 52 53 // close the file 54 fclose($file_handle); 55 //delete file 56 unlink($filename); 57 } //end of mode loop 58 59echo "Done\n"; 60?> 61--EXPECT-- 62*** Testing fgetcsv() : reading the line which is without csv fields *** 63 64-- Testing fgetcsv() with file opened using r mode -- 65array(1) { 66 [0]=> 67 string(39) "This is line of text without csv fields" 68} 69int(40) 70bool(false) 71 72-- Testing fgetcsv() with file opened using rb mode -- 73array(1) { 74 [0]=> 75 string(39) "This is line of text without csv fields" 76} 77int(40) 78bool(false) 79 80-- Testing fgetcsv() with file opened using rt mode -- 81array(1) { 82 [0]=> 83 string(39) "This is line of text without csv fields" 84} 85int(40) 86bool(false) 87 88-- Testing fgetcsv() with file opened using r+ mode -- 89array(1) { 90 [0]=> 91 string(39) "This is line of text without csv fields" 92} 93int(40) 94bool(false) 95 96-- Testing fgetcsv() with file opened using r+b mode -- 97array(1) { 98 [0]=> 99 string(39) "This is line of text without csv fields" 100} 101int(40) 102bool(false) 103 104-- Testing fgetcsv() with file opened using r+t mode -- 105array(1) { 106 [0]=> 107 string(39) "This is line of text without csv fields" 108} 109int(40) 110bool(false) 111 112-- Testing fgetcsv() with file opened using a+ mode -- 113array(1) { 114 [0]=> 115 string(39) "This is line of text without csv fields" 116} 117int(40) 118bool(false) 119 120-- Testing fgetcsv() with file opened using a+b mode -- 121array(1) { 122 [0]=> 123 string(39) "This is line of text without csv fields" 124} 125int(40) 126bool(false) 127 128-- Testing fgetcsv() with file opened using a+t mode -- 129array(1) { 130 [0]=> 131 string(39) "This is line of text without csv fields" 132} 133int(40) 134bool(false) 135 136-- Testing fgetcsv() with file opened using w+ mode -- 137array(1) { 138 [0]=> 139 string(39) "This is line of text without csv fields" 140} 141int(40) 142bool(false) 143 144-- Testing fgetcsv() with file opened using w+b mode -- 145array(1) { 146 [0]=> 147 string(39) "This is line of text without csv fields" 148} 149int(40) 150bool(false) 151 152-- Testing fgetcsv() with file opened using w+t mode -- 153array(1) { 154 [0]=> 155 string(39) "This is line of text without csv fields" 156} 157int(40) 158bool(false) 159 160-- Testing fgetcsv() with file opened using x+ mode -- 161array(1) { 162 [0]=> 163 string(39) "This is line of text without csv fields" 164} 165int(40) 166bool(false) 167 168-- Testing fgetcsv() with file opened using x+b mode -- 169array(1) { 170 [0]=> 171 string(39) "This is line of text without csv fields" 172} 173int(40) 174bool(false) 175 176-- Testing fgetcsv() with file opened using x+t mode -- 177array(1) { 178 [0]=> 179 string(39) "This is line of text without csv fields" 180} 181int(40) 182bool(false) 183Done 184