User Tools

Site Tools


uphp:functions:sprintf

sprintf

WMPRO, WMMINI FW >= 1.0 WMMEGA FW >= 2.0

Return a formatted string

Description

string sprintf ( string $format [, mixed $values ... ] )

This function will return a string produced according to the format string using the passed values. The format string is composed of literal text and/or conversion specifiers. Each conversion specifier fetches one parameter from the values.

Parameters

$format: A string with literal text and/or Conversion Specifiers

$values: Integer, float or string values to be used to produce the formatted string

Return Values

Formatted string with all supported conversion specifiers replaced with the converted value

Conversion Specifiers

A conversion specification sequence consists of a % character followed by one or more of these options in order ending with the required Conversion Type Character:

  1. Sign: Optional + (to be used on a number). By default, only the - sign is used on a number if it's negative. This specifier forces positive numbers to have the + sign attached as well.
  2. Padding: Optional 0 to pad results with zeroes (to be used on a number with a specified Width). The default is to pad with spaces.
  3. Alignment: Optional - for left-justified. The default is right-justified.
  4. Width: Optional integer string, which specifies the minimum number of characters for this conversion.
  5. Precision: Optional in the form of a period . followed by an integer string that specifies how many decimal digits should be displayed for floating-point numbers. When using this specifier on a string, it acts as a cutoff point, setting a maximum character limit to the string.
  6. Conversion Type: Required case-sensitive character which specifies how to format the passed values:
Conversion Type CharacterParameter Value TypeDescription of Returned Conversion
cIntThe character with that ASCII value
dIntA (possibly signed) decimal number
fFloatA floating-point number
sStringA string
XIntA hexadecimal number (with uppercase letters)
%(none)A literal percentage character

Any text in the format string which is not part of a conversion specification sequence (starting with % and ending with a Conversion Type Character) will be placed into the returned string as literal text, unchanged.

Notes

The mainline PHP specification for this function can be found at http://php.net/manual/en/function.sprintf.php and is useful for further information. However, the uPHP implementation does not currently support all of the options mentioned there.

See Also

printf() - Print a formatted string to standard output

uphp/functions/sprintf.txt · Last modified: 2021/09/13 05:57 (external edit)