Using the sprintf() function

sprintf($format, $val1[, val2] ...)

Data type code

CharacterFunction
s the value as a string
d the value as an integer
f the value as a floating-point number
e the value as a exponential
c an integer value as its ASCII character
b an integer value a binary number
o an integer value an octal number
x an integer value as a hexadecimal number (lowercase)
X an integer value as a hexadecimal number (uppercase)

Parts of a format code

SpecifierRequired?
% yes
sign no
alignment no
padding no
width no
precision no
data type yes

Back