Home Tutorial Php Phpfiles PHP fscanf() function and example

 
 

Share on Google+Share on Google+
PHP fscanf() function and example
Posted on: October 29, 2009 at 12:00 AM
Advertisement
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

Advertisement

Related Tags for PHP fscanf() function and example:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 29, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com