Searching...
Monday 8 October 2012

Php Fscanf Example

10:19 pm

Php Fscanf Example

Php Fscanf Example :

fscanf():  this function parses the input from an open file according to the specified format.

Fscanf(file handle,format);

Create a file with name emp.txt in your application folder the following contents.
<body bgcolor="marron" text ="white">
    <?php
    echo "<h1>";
    $fp = fopen("emp.txt","r");
   
    ?>
    <table style="font-family: verdana;font-size: 20px; background-image: url(Photo0104)" border="1" width="50%" align="center">
        <caption> Emploee details</caption>
        <tr height="60">
            <th> EMP NO</th>
            <th> EMP Name</th>
            <th> Sal</th>
        </tr>
        <?php
        while(!feof($fp))
        {
        $data =fscanf($fp,"%d%s%f");
        //print_r($data);
        echo "<tr height=50>";
            echo "<td>".$data[0]."</td>";
            echo "<td>".$data[1]."</td>";
            echo "<td>".$data[2]."</td>";
           
        }
        echo "</table>";
        fclose($fp);
        ?>
</body>

OutPut:

Emploee details EMP NO EMP Name Sal
101 penna 120000
102 raju 130000
103 obulesu 140000
104 maruti 150000

Php Fscanf Example, php, fscabf(), fscanf, scanf, fscanf example, 

1 comments: