The fscanf() function parses the input from an open file according to the specified format.
PHP fscanf() Function has the following syntax.
fscanf(file,format,mixed)
Parameter | Is Required | Description |
---|---|---|
file | Required. | File to check |
format | Required. | Format. |
mixed | Optional. | Data |
Possible format values:
Additional format values. These are placed between the % and the letter (example %.2f):
Multiple additional format values must be in the same order as above.
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.
<?php/*w w w .j a v a2s .co m*/
$handle = fopen("users.txt", "r");
while ($userinfo = fscanf($handle, "%s\t%s\n")) {
list ($name, $profession) = $userinfo;
print $name;
print $profession;
}
fclose($handle);
?>