Join Up!
96807 members and counting!

 
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links 
search for in the  
previousfreadfseeknext
Last updated: Tue, 29 Oct 2002
view the printer friendly version or the printer friendly version with notes or change language to Czech | Finnish | German

fscanf

(PHP 4 >= 4.0.1)

fscanf -- Parses input from a file according to a format

Description

mixed fscanf ( int handle, string format [, string var1])

The function fscanf() is similar to sscanf(), but it takes its input from a file associated with handle and interprets the input according to the specified format. 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.

Any whitespace in the format string matches any whitespace in the input stream. This means that even a tab \t in the format string can match a single space character in the input stream.

Ejemplo 1. fscanf() Example

$fp = fopen ("users.txt","r");
while ($userinfo = fscanf ($fp, "%s\t%s\t%s\n")) {
    list ($name, $profession, $countrycode) = $userinfo;
    //... do something with the values
}
fclose($fp);

Ejemplo 2. users.txt

javier  argonaut        pe
hiroshi sculptor        jp
robert  slacker us
luigi   florist it

See also fread(), fgets(), fgetss(), sscanf(), printf(), and sprintf().

User Contributed Notes
fscanf
add a note about notes
There are no user contributed notes for this page.
previousfreadfseeknext
Last updated: Tue, 29 Oct 2002
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by: http://phpbuilder.com/
Last updated: Thu Oct 31 18:34:28 2002 EST