PHP Code to read data from txt file and display it in html table

PHP Code:

<!DOCTYPE html>
<html>
    <head>
        <style>
            td{
                padding: 5px;
                font-size: 20px;
            }
        </style>
    </head>
<body>
<h3>Php Code to read data from txt file and display it in html table</h2>

<?php
    $myfile = fopen("program4.txt", "r") or die("Unable to open file!");
    $data = fread($myfile,filesize("program4.txt"));
    $result = explode(',', $data);
?>
<table border="1">
    <tr>
        <td><?php echo $result[0]; ?></td>
    </tr>
    <tr>
        <td><?php echo $result[1]; ?></td>
    </tr>
    <tr>
        <td><?php echo $result[2]; fclose($myfile); ?></td>
    </tr>
</table>

</body>
</html>

Output:

Comments

Popular posts from this blog

PHP Code to print first 10 Fibonacci Numbers

Create a simple HTML page to demonstrate the use of different tags

Use Tables to provide layout to your web page.