PHP fscanf() Function Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The fscanf() function is an inbuilt function in PHP that parses the file's input according to format, i.e., it accepts the input from a file that is associated with the stream & the input will be interpreted according to the specified format. This function is similar to sscanf() function. Any whitespace in the input stream is compared with any whitespace in the format string, i.e. the single space character in the input stream will be compared with the tab (\t) in the format string. For every call, this function will read one line from the file. Syntax: array|int|false|null fscanf( resource $stream, string $format, mixed &...$vars ) Parameters: This function has three parameters, which are described below: stream: The file system pointer resource will be created with the help of the fopen() function.format: The documentation for the sprintf() function describes the interpreted format for strings.vars: This parameter specifies optional values that are assigned to it.Return Values: The function will return an array if only two values are provided, but if an optional parameter is also passed by reference, it will return the number of assigned values.When there are not enough substrings in the string to match the expected format, null will be returned, and false will be returned for any other errors.Example 1: This example illustrates the basic use of the fscanf() function in PHP. PHP <?php $file = fopen("text.txt","r") ; $data = fscanf($file,"%s%s") ; foreach($data as $value){ var_dump($value) ; } ?> Output: string(2) "Hi" string(13) "GeeksforGeeks" Example 2: This is another example that illustrates the basic use of the fscanf() function in PHP. PHP <?php $file = fopen("text.txt","r") ; $data = fscanf($file,"%s%s") ; var_dump($data) ; ?> Output: array(2) { [0] => string(2) "Hi" [1] => string(13) "GeeksforGeeks" } Reference: https://www.php.net/manual/en/function.fscanf.php Comment More infoAdvertise with us Next Article PHP | fstat( ) Function N neeraj3304 Follow Improve Article Tags : PHP PHP-function PHP-Filesystem Similar Reads PHP | fstat( ) Function The fstat() function in PHP is an inbuilt function which is used to return information about an open file. The file name is sent as a parameter to the fstat() function and it returns an array with the following elements : Numeric Associative Description 0 dev Device number 1 ino inode number* 2 mode 3 min read PHP | fstat( ) Function The fstat() function in PHP is an inbuilt function which is used to return information about an open file. The file name is sent as a parameter to the fstat() function and it returns an array with the following elements : Numeric Associative Description 0 dev Device number 1 ino inode number* 2 mode 3 min read PHP | fseek( ) Function The fseek() function in PHP is an inbuilt function which is used to seek in an open file. It moves the file pointer from its current position to a new position, forward or backward specified by the number of bytes. The file and the offset are sent as parameters to the fseek() function and it returns 2 min read PHP | fseek( ) Function The fseek() function in PHP is an inbuilt function which is used to seek in an open file. It moves the file pointer from its current position to a new position, forward or backward specified by the number of bytes. The file and the offset are sent as parameters to the fseek() function and it returns 2 min read PHP | fgetc( ) Function The fgetc() function in PHP is an inbuilt function which is used to return a single character from an open file. It is used to get a character from a given file pointer. The file to be checked is used as a parameter to the fgetc() function and it returns a string containing a single character from t 2 min read PHP | fgetc( ) Function The fgetc() function in PHP is an inbuilt function which is used to return a single character from an open file. It is used to get a character from a given file pointer. The file to be checked is used as a parameter to the fgetc() function and it returns a string containing a single character from t 2 min read Like