PHP fscanf() Function

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 be checked.
format Required. Specifies the format.
mixed Optional.

Description

The fscanf() function is similar to sscanf(), but it reads from the stream associated with file Accepts input from the associated file and parses it according to the specified format To explain the input. If only two parameters are passed to this function, the parsed value will be returned as an array. Otherwise, if optional parameters are provided, this function will return the number of assignments made. Optional parameters must be passed by reference.

Tips and Comments

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

Note:Before PHP 4.3.0, the maximum number of characters that could be read from a file was 512 (or the first \n, whichever came first). Starting from PHP 4.3.0, lines of any length can be read.