123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- --TEST--
- Test fgetc() function : usage variations - different read modes
- --FILE--
- <?php
- /* read from fie using fgetc, file opened using different
- read read modes */
- echo "*** Testing fgetc() : usage variations ***\n";
- echo "-- Testing fgetc() with files opened with different read modes --\n";
- $file_modes = array( "a+", "a+b", "a+t",
- "x+", "x+b", "x+t",
- "w+", "w+b", "w+t" );
- $filename = __DIR__."/fgetc_variation4.tmp";
- foreach ($file_modes as $file_mode ) {
- echo "-- File opened in mode : $file_mode --\n";
- $file_handle = fopen($filename, $file_mode);
- if(!$file_handle) {
- echo "Error: failed to open file $filename!\n";
- exit();
- }
- $data = "fgetc\n test";
- fwrite($file_handle, $data);
- // rewind the file pointer to beginning of the file
- var_dump( rewind($file_handle) );
- var_dump( ftell($file_handle) );
- var_dump( feof($file_handle) );
- // read from file, at least 7 chars
- for($counter =0; $counter < 7; $counter ++) {
- var_dump( fgetc($file_handle) ); // expected : 1 char
- var_dump( ftell($file_handle) );
- var_dump( feof($file_handle) ); // check if end of file pointer is set
- }
- // close the file
- fclose($file_handle);
- // delete the file
- unlink($filename);
- }
- echo "Done\n";
- ?>
- --EXPECT--
- *** Testing fgetc() : usage variations ***
- -- Testing fgetc() with files opened with different read modes --
- -- File opened in mode : a+ --
- bool(true)
- int(0)
- bool(false)
- string(1) "f"
- int(1)
- bool(false)
- string(1) "g"
- int(2)
- bool(false)
- string(1) "e"
- int(3)
- bool(false)
- string(1) "t"
- int(4)
- bool(false)
- string(1) "c"
- int(5)
- bool(false)
- string(1) "
- "
- int(6)
- bool(false)
- string(1) " "
- int(7)
- bool(false)
- -- File opened in mode : a+b --
- bool(true)
- int(0)
- bool(false)
- string(1) "f"
- int(1)
- bool(false)
- string(1) "g"
- int(2)
- bool(false)
- string(1) "e"
- int(3)
- bool(false)
- string(1) "t"
- int(4)
- bool(false)
- string(1) "c"
- int(5)
- bool(false)
- string(1) "
- "
- int(6)
- bool(false)
- string(1) " "
- int(7)
- bool(false)
- -- File opened in mode : a+t --
- bool(true)
- int(0)
- bool(false)
- string(1) "f"
- int(1)
- bool(false)
- string(1) "g"
- int(2)
- bool(false)
- string(1) "e"
- int(3)
- bool(false)
- string(1) "t"
- int(4)
- bool(false)
- string(1) "c"
- int(5)
- bool(false)
- string(1) "
- "
- int(6)
- bool(false)
- string(1) " "
- int(7)
- bool(false)
- -- File opened in mode : x+ --
- bool(true)
- int(0)
- bool(false)
- string(1) "f"
- int(1)
- bool(false)
- string(1) "g"
- int(2)
- bool(false)
- string(1) "e"
- int(3)
- bool(false)
- string(1) "t"
- int(4)
- bool(false)
- string(1) "c"
- int(5)
- bool(false)
- string(1) "
- "
- int(6)
- bool(false)
- string(1) " "
- int(7)
- bool(false)
- -- File opened in mode : x+b --
- bool(true)
- int(0)
- bool(false)
- string(1) "f"
- int(1)
- bool(false)
- string(1) "g"
- int(2)
- bool(false)
- string(1) "e"
- int(3)
- bool(false)
- string(1) "t"
- int(4)
- bool(false)
- string(1) "c"
- int(5)
- bool(false)
- string(1) "
- "
- int(6)
- bool(false)
- string(1) " "
- int(7)
- bool(false)
- -- File opened in mode : x+t --
- bool(true)
- int(0)
- bool(false)
- string(1) "f"
- int(1)
- bool(false)
- string(1) "g"
- int(2)
- bool(false)
- string(1) "e"
- int(3)
- bool(false)
- string(1) "t"
- int(4)
- bool(false)
- string(1) "c"
- int(5)
- bool(false)
- string(1) "
- "
- int(6)
- bool(false)
- string(1) " "
- int(7)
- bool(false)
- -- File opened in mode : w+ --
- bool(true)
- int(0)
- bool(false)
- string(1) "f"
- int(1)
- bool(false)
- string(1) "g"
- int(2)
- bool(false)
- string(1) "e"
- int(3)
- bool(false)
- string(1) "t"
- int(4)
- bool(false)
- string(1) "c"
- int(5)
- bool(false)
- string(1) "
- "
- int(6)
- bool(false)
- string(1) " "
- int(7)
- bool(false)
- -- File opened in mode : w+b --
- bool(true)
- int(0)
- bool(false)
- string(1) "f"
- int(1)
- bool(false)
- string(1) "g"
- int(2)
- bool(false)
- string(1) "e"
- int(3)
- bool(false)
- string(1) "t"
- int(4)
- bool(false)
- string(1) "c"
- int(5)
- bool(false)
- string(1) "
- "
- int(6)
- bool(false)
- string(1) " "
- int(7)
- bool(false)
- -- File opened in mode : w+t --
- bool(true)
- int(0)
- bool(false)
- string(1) "f"
- int(1)
- bool(false)
- string(1) "g"
- int(2)
- bool(false)
- string(1) "e"
- int(3)
- bool(false)
- string(1) "t"
- int(4)
- bool(false)
- string(1) "c"
- int(5)
- bool(false)
- string(1) "
- "
- int(6)
- bool(false)
- string(1) " "
- int(7)
- bool(false)
- Done
|