sprintf_basic1.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. --TEST--
  2. Test sprintf() function : basic functionality - string 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 string format ***\n";
  10. // Initialise all required variables
  11. $format = "format";
  12. $format1 = "%s";
  13. $format2 = "%s %s";
  14. $format3 = "%s %s %s";
  15. $arg1 = "arg1 argument";
  16. $arg2 = "arg2 argument";
  17. $arg3 = "arg3 argument";
  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 string format ***
  30. string(6) "format"
  31. string(13) "arg1 argument"
  32. string(27) "arg1 argument arg2 argument"
  33. string(41) "arg1 argument arg2 argument arg3 argument"
  34. Done