Jump to content

reading a text file


ocd

Recommended Posts

The goal of this file is to read in from a text file that has entered information from a forum in the following format.

 


Male:Yes:No:School:
Female:No:No:Work:
Male:Yes:Yes:Student:

 

Each time a user clicks submit on the survery, a new line is added to the text file using another PHP program that I understand and therefore omitted. I need to take the information in the text file above and present it on a webpage in a nice table... with "Number (1-15)" before it on the same <tr> but not <td>.

 

My code below basically prints one long table with all the information and question numbers that go on forever. I know why this happens in terms of the code, but I just don't know how to stop the code after each line of reading from the text file, so that a new table can be made. Can anyone help me with this? I greatly appreciate it! Thank you.

 

<?php

$page = file_get_contents('./output.txt');
$tok = strtok($page, ":");

$i = 1;
echo "<table border=1>";

while ($tok) {
echo "<tr><td>Number $i</td>";
echo "<td>$tok\n</td></tr>";
$i++;

$tok = strtok(":\r\n");
}
echo "</table>";

?>

Link to comment
https://forums.phpfreaks.com/topic/193069-reading-a-text-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.