sprintf_variation5.phpt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. --TEST--
  2. Test sprintf() function : usage variations - int formats with resource values
  3. --FILE--
  4. <?php
  5. /* Prototype : string sprintf(string $format [, mixed $arg1 [, mixed ...]])
  6. * Description: Return a formatted string
  7. * Source code: ext/standard/formatted_print.c
  8. */
  9. echo "*** Testing sprintf() : integer formats with resource values ***\n";
  10. // resource type variable
  11. $fp = fopen (__FILE__, "r");
  12. $dfp = opendir ( dirname(__FILE__) );
  13. $fp_copy = $fp;
  14. $dfp_copy = $dfp;
  15. // array of resource types
  16. $resource_types = array (
  17. $fp_copy,
  18. $dfp_copy
  19. );
  20. // various integer formats
  21. $int_formats = array(
  22. "%d", "%Ld", " %d",
  23. "\t%d", "\n%d", "%4d",
  24. "%[0-9]", "%*d"
  25. );
  26. $count = 1;
  27. foreach($resource_types as $res) {
  28. echo "\n-- Iteration $count --\n";
  29. foreach($int_formats as $format) {
  30. var_dump( sprintf($format, $res) );
  31. }
  32. $count++;
  33. };
  34. // closing the resources
  35. fclose($fp);
  36. closedir($dfp);
  37. echo "Done";
  38. ?>
  39. --EXPECTF--
  40. *** Testing sprintf() : integer formats with resource values ***
  41. -- Iteration 1 --
  42. string(%d) "%d"
  43. string(1) "d"
  44. string(%d) " %d"
  45. string(%d) " %d"
  46. string(%d) "
  47. %d"
  48. string(%d) "%s%d"
  49. string(%d) "0-9]"
  50. string(1) "d"
  51. -- Iteration 2 --
  52. string(%d) "%d"
  53. string(1) "d"
  54. string(%d) " %d"
  55. string(%d) " %d"
  56. string(%d) "
  57. %d"
  58. string(%d) "%s%d"
  59. string(%d) "0-9]"
  60. string(1) "d"
  61. Done