fscanf
fscanf
Parses input from a file according to a format
**fscanf** resource $stream string $format mixed $vars
The function is similar to
, but it takes its input from a file
associated with and interprets the
input according to the specified .
fscanf``sscanf``stream``format
Any whitespace in the format string matches any whitespace in the input
stream. This means that even a tab () in the format
string can match a single space character in the input stream.
\t
Each call to reads one line from the file.
fscanf
stream``varsThe optional assigned values.
If only two parameters were passed to this function, the values parsed will be returned as an array. Otherwise, if optional parameters are passed, the function will return the number of assigned values. The optional parameters must be passed by reference.
If there are more substrings expected in the
than there are available within ,
null will be returned. On other errors, false will be returned.
format``string
Voorbeeld: Example
<?php
$handle = fopen("users.txt", "r");
while ($userinfo = fscanf($handle, "%s\t%s\t%s\n")) {
list ($name, $profession, $countrycode) = $userinfo;
//... do something with the values
}
fclose($handle);
?>
Voorbeeld: Contents of users.txt
javier argonaut pe
hiroshi sculptor jp
robert slacker us
luigi florist it
fread``fgets``fgetss``sscanf``printf``sprintf