User Tools

Site Tools


uphp:functions:printf

printf

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

Print a formatted string to standard output

Description

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

This function will print a formatted string to the current output stream such as a web page or terminal. The output is 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

None

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 output as literal text, unchanged.

Notes

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

See Also

sprintf() - Return a formatted string

print() - Print data to the current output stream such as a web page or terminal

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