How can PHP be used to parse and organize data from a text file into a table format?

To parse and organize data from a text file into a table format using PHP, you can read the file line by line, extract the relevant data, and then output it in an HTML table structure. This can be achieved by using functions like fopen(), fgets(), explode(), and echo to format the data accordingly.

<?php
// Open the text file for reading
$filename = 'data.txt';
$file = fopen($filename, 'r');

// Output the table structure
echo '<table>';
while (!feof($file)) {
    $line = fgets($file);
    $data = explode(',', $line);
    
    echo '<tr>';
    foreach ($data as $value) {
        echo '<td>' . $value . '</td>';
    }
    echo '</tr>';
}
echo '</table>';

// Close the file
fclose($file);
?>