PHP printf() Function

The printf() function in PHP outputs a formatted string.

The related functions of printf() function are as follows:

  • sprintf()
  • vprintf()
  • vsprintf()
  • fprintf()
  • vfprintf()

Syntax

Parameter

format(required)- This parameter formats the string which is composed of zero or more directives where the ordinary characters (excluding %) that are copied directly to the result and conversion specifications.

The possible format values are as follows:

  • %% – Returns a percent sign
  • %b – Binary number
  • %c – The character according to the ASCII value
  • %d – Signed decimal number (negative, zero or positive)
  • %e – Scientific notation using a lowercase (e.g. 1.2e+2)
  • %E – Scientific notation using a uppercase (e.g. 1.2E+2)
  • %u – Unsigned decimal number (equal to or greather than zero)
  • %f – Floating-point number (local settings aware)
  • %F – Floating-point number (not local settings aware)
  • %g – shorter of %e and %f
  • %G – shorter of %E and %f
  • %o – Octal number
  • %s – String
  • %x – Hexadecimal number (lowercase letters)
  • %X – Hexadecimal number (uppercase letters)

Return

This function returns the length of the outputted string.

Example 1

Output

Example 2

Output

Example 3

Output

Example 4

Output

Pin It on Pinterest

Share This