I have a list of names (first and last) along with their emails saved onto a .txt. file. I am trying to output the data and format it within a table, but it doesn't seem to come out correctly.
Text file:
John Doe
jdoe@email.com
Jane Smith
jsmith@email.com
PHP/HTML:
<table>
<tr>
<td>Name:</td>
<td>Email:</td>
</tr>
<?php
$contents = file("File.txt");
$lines = count($contents);
while($lines != 0) {
echo "<tr>";
foreach($contents as $field) {
echo "<td>" . $field . "</td>";
}
echo "<tr>";
$lines--;
}
?>
</table>
Ouput:
Name: Email:
John Doe
jdoe@email.com
Jane Smith
jsmith@email.com
No matter what I do, everything is entered in a new row. Any suggestions? Thanks in advance.