Current Location: Home> Function Categories> fprintf

fprintf

Write the formatted string to the stream
Name:fprintf
Category:String
Programming Language:php
One-line Description:Writes the formatted string to the specified output stream.

Definition and usage

fprintf() function writes the formatted string to the specified output stream (for example: a file or a database).

The arg1 , arg2 , arg++ parameters will be inserted into the percent sign (%) symbol in the main string. This function is executed step by step. At the first % symbol, insert arg1 , at the second % symbol, insert arg2 , and so on.

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

Related functions:

  • printf()
  • sprintf()
  • vfprintf()
  • vprintf()
  • vsprintf()

grammar

 fprintf ( stream , format , arg1 , arg2 , arg ++ )
parameter describe
stream Required. Specifies where to write/output strings.
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 - 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 specifier.
    For example: %'x20s (using "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 multiple additional format values ​​are used, they must be used in the order above.

arg1 Required. Specifies the parameters inserted into the first % symbol in the format string.
arg2 Optional. Specifies the parameter inserted into the second % symbol in the format string.
arg++ Optional. Specifies the parameters inserted into the third, fourth, etc. % symbols in the format string.
Similar Functions
Popular Articles