Returns a string produced according to the formatting
string format.
The format string is composed of zero or more
directives: ordinary characters (excluding %) that are copied directly to the result, and
conversion
specifications, each of which results in fetching
its own parameter. This applies to both
sprintf() and printf().
Each conversion specification consists of a percent sign
(%), followed by one or more of
these elements, in order:
An optional padding specifier that says what
character will be used for padding the results to the
right string size. This may be a space character or a 0 (zero character). The default is
to pad with spaces. An alternate padding character can be
specified by prefixing it with a single quote ('). See the examples below.
An optional alignment specifier that says if
the result should be left-justified or right-justified.
The default is right-justified; a
- character here will make it left-justified.
An optional number, a width specifier that says how
many characters (minimum) this conversion should result
in.
An optional precision specifier that says how
many decimal digits should be displayed for
floating-point numbers. This option has no effect for
other types than float. (Another function useful for
formatting numbers is
number_format().)
A type
specifier that says what type the argument
data should be treated as. Possible types:
As of PHP version 4.0.6 the format string supports
argument numbering/swapping. Here is an example:
See also printf(),
sscanf(), fscanf(),
vsprintf(), and
number_format().