PHP fscanf() Function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes 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 fscanf() Function 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 asin( ) Function Trigonometry is an important part of mathematics and PHPâs math functions provides us with some functions which are very useful for calculations involving trigonometry. One of such function is asin() function. The asin() function in PHP is used to find the arc sine of a number in radians. We already 2 min read PHP atan( ) Function Trigonometry is an important part of mathematics and PHPâs math functions provides us with some functions which are very useful for calculations involving trigonometry. One of such function is atan() function. The atan() function in PHP is used to find the arc tangent of an argument passed to it whi 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 | fgets( ) Function The fgets() function in PHP is an inbuilt function which is used to return a line from an open file. It is used to return a line from a file pointer and it stops returning at a specified length, on end of file(EOF) or on a new line, whichever comes first. The file to be read and the number of bytes 2 min read PHP fputs( ) Function The fputs() function in PHP is an inbuilt function which is used to write to an open file. The fputs() function stops at the end of the file or when it reaches the specified length passed as a parameter, whichever comes first. The file, string, and the length that has to be written are sent as param 3 min read PHP cos( ) Function Trigonometry is an important part of mathematics and PHPâs math functions provides us with some functions which are very useful for calculations involving trigonometry. The cos()function in PHP is used to find the cosine of a number. The cos() function returns a float value between -1 and 1, which r 2 min read PHP | fgetss( ) Function The fgetss() function in PHP is an inbuilt function which is used to return a line from an open file after removing HTML and PHP tags from the respective file. The fegtss() function stops returning at a specified length, on end of file(EOF) or on a new line, whichever comes first. The file to be re 2 min read PHP eval() Function PHP eval() function in PHP is an inbuilt function that evaluates a string as PHP code. Syntax: eval( $string ) Parameters: This function accepts a single parameter as shown in the above syntax and described below. $string: It must consist of a valid PHP code to be evaluated but should not contain op 2 min read Like