- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
fscanf() function in PHP
The fscanf() function parses input from an open file according to a specified format. It returns the values parsed as an array, if only two parameters were passed.
Syntax
fscanf(file_pointer, format, mixed)
Parameters
file_pointer − A file system pointer resource created using fopen().
format − Specify the format. Here are the values:
- %% - Returns a percent
- %b - Binary number
- %c - The character according to the ASCII value
- %f - Floating-point number
- %F - Floating-point number
- %o - Octal number
- %s - String
- %d - Signed decimal number
- %e - Scientific notation
- %u - Unsigned decimal number
- %x - Hexadecimal number for lowercase letters
- %X - Hexadecimal number for uppercase letters
mixed − Specify the assigned values. Optional.
Return
The fscanf() function returns the values parsed as an array, if only two parameters were passed.
Example
<?php $file_pointer = fopen("new.txt", "r"); while ($playerrank = fscanf($handle, "%s\t%d
")) { list ($name, $rank) = $playerrank; echo “$name got rank $rank.”; } fclose($file_pointer); ?>
Output
Amit got rank 2
Advertisements