123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- --TEST--
- Test fscanf() function: usage variations - octal formats with boolean
- --FILE--
- <?php
- /* Test fscanf() to scan boolean data using different octal format types */
- $file_path = __DIR__;
- echo "*** Test fscanf(): different octal format types with boolean data ***\n";
- // create a file
- $filename = "$file_path/fscanf_variation32.tmp";
- $file_handle = fopen($filename, "w");
- if($file_handle == false)
- exit("Error:failed to open file $filename");
- // array of boolean types
- $bool_types = array (
- true,
- false,
- TRUE,
- FALSE,
- );
- $octal_formats = array( "%o",
- "%ho", "%lo", "%Lo",
- " %o", "%o ", "% o",
- "\t%o", "\n%o", "%4o",
- "%30o", "%[0-7]", "%*o"
- );
- $counter = 1;
- // writing to the file
- foreach($bool_types as $value) {
- @fprintf($file_handle, $value);
- @fprintf($file_handle, "\n");
- }
- // closing the file
- fclose($file_handle);
- // opening the file for reading
- $file_handle = fopen($filename, "r");
- if($file_handle == false) {
- exit("Error:failed to open file $filename");
- }
- $counter = 1;
- // reading the values from file using different octal formats
- foreach($octal_formats as $octal_format) {
- // rewind the file so that for every foreach iteration the file pointer starts from bof
- rewind($file_handle);
- echo "\n-- iteration $counter --\n";
- while( !feof($file_handle) ) {
- try {
- var_dump(fscanf($file_handle,$octal_format));
- } catch (ValueError $exception) {
- echo $exception->getMessage() . "\n";
- }
- }
- $counter++;
- }
- echo "\n*** Done ***";
- ?>
- --CLEAN--
- <?php
- $file_path = __DIR__;
- $filename = "$file_path/fscanf_variation32.tmp";
- unlink($filename);
- ?>
- --EXPECT--
- *** Test fscanf(): different octal format types with boolean data ***
- -- iteration 1 --
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- bool(false)
- -- iteration 2 --
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- bool(false)
- -- iteration 3 --
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- bool(false)
- -- iteration 4 --
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- bool(false)
- -- iteration 5 --
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- bool(false)
- -- iteration 6 --
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- bool(false)
- -- iteration 7 --
- Bad scan conversion character " "
- Bad scan conversion character " "
- Bad scan conversion character " "
- Bad scan conversion character " "
- bool(false)
- -- iteration 8 --
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- bool(false)
- -- iteration 9 --
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- bool(false)
- -- iteration 10 --
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- bool(false)
- -- iteration 11 --
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- array(1) {
- [0]=>
- int(1)
- }
- NULL
- bool(false)
- -- iteration 12 --
- array(1) {
- [0]=>
- string(1) "1"
- }
- array(1) {
- [0]=>
- NULL
- }
- array(1) {
- [0]=>
- string(1) "1"
- }
- array(1) {
- [0]=>
- NULL
- }
- bool(false)
- -- iteration 13 --
- array(0) {
- }
- NULL
- array(0) {
- }
- NULL
- bool(false)
- *** Done ***
|