faqts : Computers : Programming : Languages : PHP : Common Problems : Files

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 7 people (71%) answered Yes
Recently 4 of 6 people (67%) answered Yes


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.
// Add headings as you like
$table.="<TR><TH>Heading 1</TH><TH>Heading 2</TH></TR>";
// Loop though the file
 // This will be a new line in the table.
 // Now we get the file a line at a time.
 // 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.
 } // End looping through the array
 $table.="</TR>"; // End the table row
} // End looping through the file
// Now end that 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>";