fscanf_variation1.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. --TEST--
  2. Test fscanf() function: usage variations - return type without third argument
  3. --FILE--
  4. <?php
  5. /* test fscanf() for its return type */
  6. $file_path = __DIR__;
  7. echo "*** Testing fscanf(): for its return type without third argument ***\n";
  8. // create a file
  9. $filename = "$file_path/fscanf_variation1.tmp";
  10. $file_handle = fopen($filename, "w");
  11. if($file_handle == false)
  12. exit("Error:failed to open file $filename");
  13. @fwrite($file_handle, "hello_world ");
  14. @fwrite($file_handle, 12345);
  15. fclose($file_handle);
  16. // open file for reading
  17. $file_handle = fopen($filename, "r");
  18. // capturing the return value from fscanf() called without third argument
  19. $return_value = fscanf($file_handle, "%s");
  20. var_dump( is_array($return_value), $return_value); // return type is an array
  21. fclose($file_handle);
  22. echo "\n*** Done ***";
  23. ?>
  24. --CLEAN--
  25. <?php
  26. $file_path = __DIR__;
  27. $filename = "$file_path/fscanf_variation1.tmp";
  28. unlink($filename);
  29. ?>
  30. --EXPECT--
  31. *** Testing fscanf(): for its return type without third argument ***
  32. bool(true)
  33. array(1) {
  34. [0]=>
  35. string(11) "hello_world"
  36. }
  37. *** Done ***