reading a text file with the correct while loop
Posted: Tue Feb 23, 2010 8:39 am
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
The goal of this file is to read in from a text file that has entered information from a forum in the following format.
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 web page 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.
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
The goal of this file is to read in from a text file that has entered information from a forum in the following format.
Code: Select all
Male:Yes:No:School:
Female:No:No:Work:
Male:Yes:Yes:Student:
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.
Code: Select all
<?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>";
?>
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: