php fscanf function
fscanf
(PHP 4" = 4.0.1, PHP 5)
fscanf - Parses input file format according to
Description
mixed fscanf (resource$processing, string$format[, mixed&$...])
The function fscanf() is similar to sscanf(), but takes inputs from an archive and processes and interprets the inputs according to a specified format, which is described in the literature for sprintf().
Any whitespace in the format string matches any whitespace in the input stream. This means that even a tag T in the format string can match a single whitespace character in the input stream.
Each call to fscanf() reads one line from the file.
Parameters
Handle
A file system pointer resource, usually created using the fopen() function.
Format
Specifies the format of the file as described in sprintf().
...
Optional specified value.
Return value
If there are only two parameters, the value parsed by this function will return an array. Otherwise, if optional arguments are passed, the function returns the specified number of values. Optional parameters must be passed by reference.
Modify
Release Notes
At the time before 4.3.0, the maximum number of characters read from a file was 512 (or the first nitro, both of which were first). But now, arbitrarily long lines will be read and scanned.
Example
Example #1 fscanf ( ) as an example
$handle = fopen("users.txt", "r");
while ($userinfo = fscanf($handle, "%st%st%sn")) {
List ($name, $profession, $countrycode) = $userinfo;
//... do something with the values
}
fclose($handle);
?>