Entry
I wish to capture colon-delimited data from a txt file and to break it into lines and from there columns to format into an HTML table. How?
Sep 7th, 2004 02:06
Karl Vegar Larsen, Jon Thomas, http://www.php.net
//Start opening that file usingn fopen
$fh=fopen("filename", "r");
// Lets initiate a table i a variable.
$table="<TABLE>";
// Add headings as you like
$table.="<TR><TH>Heading 1</TH><TH>Heading 2</TH></TR>";
// Loop though the file
while(!eof($fh)){
// This will be a new line in the table.
$table.="<TR>";
// Now we get the file a line at a time.
$line=fread($fh);
// Lets split up that line.
$field=explode(";", $line);
// Loop through that array.
for($t=0; $t<count($field); $t++){
// Add the fields to the table.
$table.="<TD>$field[$t]</TD>";
} // End looping through the array
$table.="</TR>"; // End the table row
} // End looping through the file
// Now end that table
$table.="</TABLE>";
// Now make the rest of the page.
echo "<HTML>";
echo "<HEAD><TITLE>Table page</TITLE></HEAD>";
echo "<BODY>";
// Display the table
echo $table;
// Finish the page.
echo "</BODY></HTML>";