PHP fscanf()Functions


PHP Filesystem 参考手册Complete PHP Filesystem Reference

Definition and Usage

The fscanf() function parses input from an open file according to the specified format.

Syntax

fscanf(file,format,mixed)

Parameters Description
file Required. Specifies the file to check.
format Required. Specifies the format.

Possible format values:

  • %% - Returns a percent sign %
  • %b - Binary number
  • %c - The character corresponding to the ASCII value
  • %d - Signed decimal number
  • %e - Scientific notation (e.g.: 1.2e+2)
  • %u - Unsigned decimal number
  • %f - Floating-point number (locale-aware)
  • %F - Floating-point number (non-locale-aware)
  • %o - Octal number
  • %s - String
  • %x - Hexadecimal number (lowercase letters)
  • %X - Hexadecimal number (uppercase letters)

Additional format values. Must be placed between the % and the letter (e.g. %.2f):

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

Note:If multiple of the above format values are used, they must be used in the order listed above and must not be reordered.

mixed Optional.


Tips and Notes

Note: Any whitespace in the format string matches any whitespace in the input stream. This means that a tab \t in the format string will also match a single space character in the input stream.


PHP Filesystem 参考手册Complete PHP Filesystem Reference Other Extensions