sprintf_variation52.phpt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. --TEST--
  2. Test sprintf() function : usage variations - typical format strings
  3. --FILE--
  4. <?php
  5. echo "*** Testing sprintf() : with typical format strings ***\n";
  6. // initialising required variables
  7. $tempnum = 12345;
  8. $tempstring = "abcdefghjklmnpqrstuvwxyz";
  9. echo"\n-- Testing for '%%%.2f' as the format parameter --\n";
  10. var_dump(sprintf("%%%.2f", 1.23456789e10));
  11. echo"\n-- Testing for '%%' as the format parameter --\n";
  12. var_dump(sprintf("%%", 1.23456789e10));
  13. echo"\n-- Testing for precision value more than maximum --\n";
  14. var_dump(sprintf("%.988f", 1.23456789e10));
  15. echo"\n-- Testing for invalid width(-15) specifier --\n";
  16. try {
  17. var_dump(sprintf("%030.-15s", $tempstring));
  18. } catch (ValueError $e) {
  19. echo $e->getMessage(), "\n";
  20. }
  21. echo"\n-- Testing for '%X' as the format parameter --\n";
  22. var_dump(sprintf("%X", 12));
  23. echo"\n-- Testing for multiple format parameters --\n";
  24. var_dump(sprintf("%d %s %d\n", $tempnum, $tempstring, $tempnum));
  25. echo"\n-- Testing for excess of mixed type arguments --\n";
  26. var_dump(sprintf("%s", $tempstring, $tempstring, $tempstring));
  27. echo "Done";
  28. ?>
  29. --EXPECTF--
  30. *** Testing sprintf() : with typical format strings ***
  31. -- Testing for '%%%.2f' as the format parameter --
  32. string(15) "%12345678900.00"
  33. -- Testing for '%%' as the format parameter --
  34. string(1) "%"
  35. -- Testing for precision value more than maximum --
  36. Notice: sprintf(): Requested precision of 988 digits was truncated to PHP maximum of %d digits in %s on line %d
  37. string(65) "12345678900.00000000000000000000000000000000000000000000000000000"
  38. -- Testing for invalid width(-15) specifier --
  39. Unknown format specifier "-"
  40. -- Testing for '%X' as the format parameter --
  41. string(1) "C"
  42. -- Testing for multiple format parameters --
  43. string(39) "12345 abcdefghjklmnpqrstuvwxyz 12345
  44. "
  45. -- Testing for excess of mixed type arguments --
  46. string(24) "abcdefghjklmnpqrstuvwxyz"
  47. Done