Current Location: Home> Function Categories> vprintf

vprintf

Output formatted string
Name:vprintf
Category:String
Programming Language:php
One-line Description:Output a formatted string.

Definition and usage

vprintf() function outputs a formatted string.

Unlike printf() , the parameters in vprintf() are in the array. The array element will be inserted at the percent sign (%) symbol in the main string. This function is executed step by step. At the first % symbol, insert the first array element, at the second % symbol, insert the second array element, and so on.

Note: If the % symbol is more than the arg parameter, you must use placeholders. The placeholder is inserted into the % symbol and consists of a number and "\$". See Example 2.

Related functions:

  • fprintf()
  • printf()
  • sprintf()
  • vfprintf()
  • vsprintf()

grammar

 vprintf ( format , argarray )
parameter describe
format

Required. Specifies the string and how to format the variables in it.

Possible format values:

  • %% - Returns a percent sign
  • %b - binary number
  • %c - Characters corresponding to ASCII value
  • %d - Decimal number containing positive and negative signs (negative number, 0, positive number)
  • %e - Use lowercase scientific notation (e.g. 1.2e+2)
  • %E - Scientific notation using capitals (e.g. 1.2E+2)
  • %u - Decimal number without signs (greater than or equal to 0)
  • %f - Floating point number (local setting)
  • %F - Floating point number (non-local setting)
  • %g - shorter %e and %f
  • %G - Shorter %E and %f
  • %o - octal number
  • %s - string
  • %x - Hexadecimal number (lowercase letters)
  • %X - Hexadecimal number (caps)

Additional format value. Necessarily placed between % and letters (for example %.2f):

  • + (Present + or - before the number to define the positive and negative nature of the number. By default, only negative numbers are marked, and positive numbers are not marked)
  • ' (Specify what to use as padding, default is a space. It must be used with the width specifyer. For example: %'x20s (use "x" as padding))
  • - (Left adjustment variable value)
  • [0-9] (Specify the minimum width of the variable value)
  • .[0-9] (Specify the number of decimal places or maximum string length)

Note: If you use multiple format values, they must be in the above order.

argarray Required. An array with parameters that are inserted into the % symbol in the format string.
Similar Functions