October 22nd, 2000, 10:38 PM
-
Hi,
I want to open a text file and print it to a page. It first has to...
1. split the file by line...
2. split each line (by tabs)
I then want to put the values into a table in the format of...
<table>
<tr>(line one)
<td>element one</td>
<td>element two</td>
etc..
</tr> (end line one)
<tr>(line two)
etc
etc
</table>
can anyone help me out...
so far I have this..
<?
$fp = fopen("filename.txt", "r");
$contents = fread($fp, filesize("filename.txt"));
fclose($fp);
$newArray=explode("t", $contents);
while (list($key,$value) = each($newArray)){
echo "<td>$value</td>";
}
$numlines=count($newArray);
echo "<br>Count is:$numlines<br>";
$n=0;
$elementArray=array();
for ($i=0;$i<$numlines;$i++)
{
$elementArray[$n]=split(",",$newArray[$i]);
$n++;
//echo"First Element:$elementArray[$i][$n]<br>";
}
?>
the above code only splits file based on tabs... i couldn't get it to do both.
thanks in advance.
dave
October 22nd, 2000, 11:14 PM
-
//Put each line into an array
$file = file("yourfile");
print '<table>';
while (list($key,$val) = each($file)) {
$str = explode("t", $val);
print '<tr>';
print '<td>'.$str[0].'</td>'
print '<td>'.$str[1].'</td>'
print '</tr>';
}
print '</table>';