vfprintf_basic.phpt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. --TEST--
  2. Test vfprintf() function : basic functionality
  3. --CREDITS--
  4. Felix De Vliegher <felix.devliegher@gmail.com>
  5. --INI--
  6. precision=14
  7. --FILE--
  8. <?php
  9. /* Prototype : int vfprintf(resource stream, string format, array args)
  10. * Description: Output a formatted string into a stream
  11. * Source code: ext/standard/formatted_print.c
  12. * Alias to functions:
  13. */
  14. function writeAndDump($fp, $format, $args)
  15. {
  16. ftruncate( $fp, 0 );
  17. $length = vfprintf( $fp, $format, $args );
  18. rewind( $fp );
  19. $content = stream_get_contents( $fp );
  20. var_dump( $content );
  21. var_dump( $length );
  22. }
  23. echo "*** Testing vfprintf() : basic functionality ***\n";
  24. // Open handle
  25. $file = 'vfprintf_test.txt';
  26. $fp = fopen( $file, "a+" );
  27. // Test vfprintf()
  28. writeAndDump( $fp, "Foo is %d and %s", array( 30, 'bar' ) );
  29. writeAndDump( $fp, "%s %s %s", array( 'bar', 'bar', 'bar' ) );
  30. writeAndDump( $fp, "%d digit", array( '54' ) );
  31. writeAndDump( $fp, "%b %b", array( true, false ) );
  32. writeAndDump( $fp, "%c %c %c", array( 65, 66, 67 ) );
  33. writeAndDump( $fp, "%e %E %e", array( 1000, 2e4, +2e2 ) );
  34. writeAndDump( $fp, "%02d", array( 50 ) );
  35. writeAndDump( $fp, "Testing %b %d %f %s %x %X", array( 9, 6, 2.5502, "foobar", 15, 65 ) );
  36. // Close handle
  37. fclose( $fp );
  38. ?>
  39. ===DONE===
  40. --CLEAN--
  41. <?php
  42. $file = 'vfprintf_test.txt';
  43. unlink( $file );
  44. ?>
  45. --EXPECTF--
  46. *** Testing vfprintf() : basic functionality ***
  47. string(17) "Foo is 30 and bar"
  48. int(17)
  49. string(11) "bar bar bar"
  50. int(11)
  51. string(8) "54 digit"
  52. int(8)
  53. string(3) "1 0"
  54. int(3)
  55. string(5) "A B C"
  56. int(5)
  57. string(35) "1.000000e+3 2.000000E+4 2.000000e+2"
  58. int(35)
  59. string(2) "50"
  60. int(2)
  61. string(35) "Testing 1001 6 2.550200 foobar f 41"
  62. int(35)
  63. ===DONE===