Home Tutorial Php Examples fscanf() example

 
 

Share on Google+Share on Google+
fscanf() example
Posted on: July 30, 2009 at 12:00 AM
Advertisement
Here you will learn about fscanf() example.

fscanf() function

function fscanf  is used for parsing the inputs from a file according to a format

Syntax

fscanf(file,format,mixed) 

Parameter

File - File is essential for running this function. There must be at least one file from which it parses the value.

Format - Format is essential. It should be specified.

Mixed is optional. 

Example:

The below example will print the name and profession of the developer. 

Begin the PHP tag.

Open the file using fopen() function.

Run the while loop until, it meets the command. 

Print it and close the file

End the PHP tag.

<?php
$handle = fopen("New Text Document .txt", "r");

while ($userinfo = fscanf($handle, "%s\t%s\n")) 
{
list ($name, $profession ) = $userinfo;
echo $name;
echo "<br>";
echo $profession;
}
fclose($handle);
?>

Advertisement

Related Tags for fscanf() 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: July 30, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com