sprintf_basic2.phpt 1018 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. --TEST--
  2. Test sprintf() function : basic functionality - integer format
  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() : basic functionality - using integer format ***\n";
  10. // Initialise all required variables
  11. $format = "format";
  12. $format1 = "%d";
  13. $format2 = "%d %d";
  14. $format3 = "%d %d %d";
  15. $arg1 = 111;
  16. $arg2 = 222;
  17. $arg3 = 333;
  18. // Calling sprintf() with default arguments
  19. var_dump( sprintf($format) );
  20. // Calling sprintf() with two arguments
  21. var_dump( sprintf($format1, $arg1) );
  22. // Calling sprintf() with three arguments
  23. var_dump( sprintf($format2, $arg1, $arg2) );
  24. // Calling sprintf() with four arguments
  25. var_dump( sprintf($format3, $arg1, $arg2, $arg3) );
  26. echo "Done";
  27. ?>
  28. --EXPECTF--
  29. *** Testing sprintf() : basic functionality - using integer format ***
  30. string(6) "format"
  31. string(3) "111"
  32. string(7) "111 222"
  33. string(11) "111 222 333"
  34. Done