fscanf_variation1.phpt 1.2 KB

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