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