printf_basic9.phpt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. --TEST--
  2. Test printf() function : basic functionality - hexadecimal format
  3. --FILE--
  4. <?php
  5. /* Prototype : int printf ( string $format [, mixed $args [, mixed $... ]] )
  6. * Description: Produces output according to format .
  7. * Source code: ext/standard/formatted_print.c
  8. */
  9. echo "*** Testing printf() : basic functionality - using hexadecimal format ***\n";
  10. // Initialise all required variables
  11. // Initialising different format strings
  12. $format = "format";
  13. $format1 = "%x";
  14. $format2 = "%x %x";
  15. $format3 = "%x %x %x";
  16. $format11 = "%X";
  17. $format22 = "%X %X";
  18. $format33 = "%X %X %X";
  19. $arg1 = 11;
  20. $arg2 = 132;
  21. $arg3 = 177;
  22. echo "\n-- Calling printf() with no arguments --\n";
  23. $result = printf($format);
  24. echo "\n";
  25. var_dump($result);
  26. echo "\n-- Calling printf() with one arguments --\n";
  27. $result = printf($format1, $arg1);
  28. echo "\n";
  29. var_dump($result);
  30. $result = printf($format11, $arg1);
  31. echo "\n";
  32. var_dump($result);
  33. echo "\n-- Calling printf() with two arguments --\n";
  34. $result = printf($format2, $arg1, $arg2);
  35. echo "\n";
  36. var_dump($result);
  37. $result = printf($format22, $arg1, $arg2);
  38. echo "\n";
  39. var_dump($result);
  40. echo "\n-- Calling printf() with three arguments --\n";
  41. $result = printf($format3, $arg1, $arg2, $arg3);
  42. echo "\n";
  43. var_dump($result);
  44. $result = printf($format33, $arg1, $arg2, $arg3);
  45. echo "\n";
  46. var_dump($result);
  47. ?>
  48. ===DONE===
  49. --EXPECTF--
  50. *** Testing printf() : basic functionality - using hexadecimal format ***
  51. -- Calling printf() with no arguments --
  52. format
  53. int(6)
  54. -- Calling printf() with one arguments --
  55. b
  56. int(1)
  57. B
  58. int(1)
  59. -- Calling printf() with two arguments --
  60. b 84
  61. int(4)
  62. B 84
  63. int(4)
  64. -- Calling printf() with three arguments --
  65. b 84 b1
  66. int(7)
  67. B 84 B1
  68. int(7)
  69. ===DONE===