sprintf_variation5.phpt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. --TEST--
  2. sprintf With signed integer
  3. --FILE--
  4. <?php
  5. /* example#5: various examples */
  6. $n = 43951789;
  7. $u = -43951789;
  8. $c = 65; // ASCII 65 is 'A'
  9. // notice the double %%, this prints a literal '%' character
  10. var_dump(sprintf("%%b = '%b'", $n)); // binary representation
  11. var_dump(sprintf("%%c = '%c'", $c)); // print the ascii character, same as chr() function
  12. var_dump(sprintf("%%d = '%d'", $n)); // standard integer representation
  13. var_dump(sprintf("%%e = '%e'", $n)); // scientific notation
  14. var_dump(sprintf("%%f = '%f'", $n)); // floating point representation
  15. var_dump(sprintf("%%o = '%o'", $n)); // octal representation
  16. var_dump(sprintf("%%s = '%s'", $n)); // string representation
  17. var_dump(sprintf("%%x = '%x'", $n)); // hexadecimal representation (lower-case)
  18. var_dump(sprintf("%%X = '%X'", $n)); // hexadecimal representation (upper-case)
  19. var_dump(sprintf("%%+d = '%+d'", $n)); // sign specifier on a positive integer
  20. var_dump(sprintf("%%+d = '%+d'", $u)); // sign specifier on a negative integer
  21. ?>
  22. --EXPECT--
  23. string(33) "%b = '10100111101010011010101101'"
  24. string(8) "%c = 'A'"
  25. string(15) "%d = '43951789'"
  26. string(18) "%e = '4.395179e+7'"
  27. string(22) "%f = '43951789.000000'"
  28. string(16) "%o = '247523255'"
  29. string(15) "%s = '43951789'"
  30. string(14) "%x = '29ea6ad'"
  31. string(14) "%X = '29EA6AD'"
  32. string(17) "%+d = '+43951789'"
  33. string(17) "%+d = '-43951789'"