PHP Text File Read Data


demo.txt

1;Aashis;Chaudhary;10
2;Urbasi;Shrestha;15
3;Gita;Kumari;20
4;Sita;Sahi;15
5;Hari;Prasad;12
-----------------------------------------------------------------------
demo.php

<!DOCTYPE html>
<html>
<head>
    <title>PHP Text File Read Data</title>
    <style type="text/css">
        *{
            font-family: arial;
            font-size: 13px;
        }
        table{
            border-collapse: collapse;
            width: 400px;
        }
        table tr{

        }
        table tr th,table tr td{
            padding: 5px;
        }
    </style>
</head>
<body>
    <h3>PHP Text File Read Data</h3>
    <?php 
    $files =file('demo.txt');
    $data = array();
    foreach ($files as $value) {
        $data[] = explode(';', $value);
    }
    ?>
    <table border="1">
        <tr>
            <th>#</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Age</th>
        </tr>

        <?php
        foreach ($data as $value) {
            echo '<tr>';
            echo '<td>'.$value[0].'</td>';
            echo '<td>'.$value[1].'</td>';
            echo '<td>'.$value[2].'</td>';
            echo '<td>'.$value[3].'</td>';
            echo '</tr>';
        }
        ?>
    </table>
</body>
</html>

Output:




Share on Google Plus

About Ram Pukar

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment