Home > Backend Development > PHP Tutorial > php fscanf function_PHP tutorial

php fscanf function_PHP tutorial

WBOY
Release: 2016-07-20 11:01:02
Original
2081 people have browsed it

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);
?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445470.htmlTechArticlephp fscanf function fscanf (PHP 4 = 4.0.1, PHP 5) fscanf - parse the input file format Mix fscanf as described (resource$processing, string$format[, mix$...]) function...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template