Home Tutorial Php Phpfiles PHP fscanf() function and example

 
 

PHP fscanf() function and example
Posted on: October 29, 2009 at 12:00 AM
In this segment of the PHP tutorial we will learn the use of PHP fscanf() file handling function and its example.

Syntax

mixed fscanf file_handle,format_specifier [, mixed &$... ] )

  • fscanf() function reads the contents of the file according to the given formatspecifier
  • Format specifier can be like the C language format specifier
  • fscanf() uses %d, %c, %s etc format specifier.
  • By default it returns mixed type.
  • But if two parameter is used then it returns array


Example of PHP fscant() Function PHP
Code for PHP fsscant() Unction PHP

<?php
    $file
=fopen("c:/rose1/ram.txt","r");

    while
($ar1=fscanf($file,"%s\t%s"))
     {
      for
($x=0;$x<sizeof($ar1);$x++)
        {
        echo
$ar1[$x];
        if
($x%2!=0)
        echo
"<br>";
        }
     }
?>
Output
first_namelast_name
ramkumar
shyamsinha

Related Tags for PHP fscanf() function and example:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.