Php fscanf Function

Source: Internet
Author: User

Php fscanf Function

Fscanf
("= 4.0.1, PHP 5" in PHP 4)

Fscanf-parse the format of the input file according

Description
Hybrid fscanf (resource $ processing, string $ format [, hybrid & $...])
The function fscanf () is similar to sscanf (), but the input required from archive and processing and interpretation is based on the specified format, which is described in the document sprintf ().

Any space Format String matches any blank input stream. This means that even if a tag T matches a single space character input stream in the format string.

Each phone fscanf () reads a row from the archive.

Parameters

Handle
A file system pointer resource is usually created using the fopen () function.

Format
Specifies the sprintf () file described in the format.

...
Optional value.


Return Value
If there are only two parameters, value parsing returns an array. Otherwise, if an optional parameter is passed, the function returns a specified number of values. Optional parameters must be passed through reference.

Modify

Version description
4.3.0 at the time prior to this, the maximum number of characters read from the file is 512 (or the first nitrogen, the two ranked first ). But now, any long row reads and scans.


Instance

For example, #1 fscanf ()

$ Handle = fopen ("users.txt", "r ");
While ($ userinfo = fscanf ($ handle, "% st % sn ")){
List ($ name, $ declaration, $ countrycode) = $ userinfo;
//... Do something with the values
}
Fclose ($ handle );
?>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.