Javatpoint Logo
Javatpoint Logo

PHP string printf() Function

PHP string printf() function predefined functions. It is used to output a formatted string. We can pass the arg1, arg2, arg++ parameters at percent (%) signs in the main string.


Parameter Description Required/Optional
format Specify the string. Following are the possible format values:
  • %% - 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)
arg1 The argument to be inserted at the first %-sign. Required
arg2 The argument to be inserted at the second %-sign. Optional
arg++ The argument to be inserted at the third,fourth, etc. %s sign optional

Example 1


We are Learning PHP 7 form JAVATPOINT.

Example 2



Example 3


With 2 decimals: 23456.00 
With no decimals: 23456

Example 4


[ Hello]
[Hello ]
[Hello PH]

Next TopicPHP String

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA