Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP fscanf() Function

PHP fscanf() Function


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual


Definition and Usage

The fscanf() function parses input from an open file according to a 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 an ASCII value
  • %d - Signed decimal number
  • %e - Scientific notation (for example: 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. They must be placed between the % and the letter (for example %.2f):

    Note:If multiple of the above format values are used, they must be used in the order shown above and cannot be rearranged.

    | | 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 also matches a single space character in the input stream.


    PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual