PHP fscanf function
The PHP fscanf function can be used to read whether there are strings or characters that meet the normal expression conditions in the file. The usage of the fscanf function is similar to the sscanf function , but the difference is that the fscanf function also has an additional $handle parameter that can be used. Compared with the sscanf function which can only parse the string content, the fscanf function can parse the content of the document file.
Basic syntax of PHP fscanf function
mixed fscanf ( $handle , $format , $mixed ... )
The first parameter of the parentheses of the fscanf function, $handle, is a file system pointer resource, which is a file resource created through fopen . The second parameter, $format, sets the regular expression to be used. For items, please refer to the parameter list on the sprintf function . The third parameter $mixed is the selected item, which can be left blank.
PHP fscanf function example
$handle = fopen("test.txt", "r");
while ($fscanf_result = fscanf($handle, "%s\t%s\t%s\n")) {
print_r($fscanf_result);
echo '<br>';
}
fclose($handle);
?>
DEF
Array( [0] => D [1] => E [2] => F )
Post a Comment
0 Comments