brain spasm... formatting a text file into html columns
Moderator: General Moderators
brain spasm... formatting a text file into html columns
got a comman and line delimited file...
want it to read in 2 columns...
the way to do this would be read the entire file and COUNT the lines and then
<table><tr><td>
loop through the first half
</td><td>
loop through the second half
</td></tr>
</table>
Right?
Anyone know what the function to OCUNT the number of lines is?
Im have a brain freeze on simple crap and really pressed for time... thanks
want it to read in 2 columns...
the way to do this would be read the entire file and COUNT the lines and then
<table><tr><td>
loop through the first half
</td><td>
loop through the second half
</td></tr>
</table>
Right?
Anyone know what the function to OCUNT the number of lines is?
Im have a brain freeze on simple crap and really pressed for time... thanks
Last edited by romeo on Tue Nov 18, 2003 10:41 am, edited 1 time in total.
try this
Mark
Code: Select all
$linecount=count(file("path/to/file.txt"));so im looking at this, and stuill having problems :)
DELETED THIS POST CAUSE IM AN IDIOT... NEW SOURCE STILL SCREWED UP BELOW
Last edited by romeo on Wed Nov 19, 2003 10:37 am, edited 1 time in total.
if yoru willing to help im mor eten willing to put php tags
DELETED THIS POST CAUSE IM AN IDIOT... NEW SOURCE STILL SCREWED UP BELOW
Last edited by romeo on Wed Nov 19, 2003 10:37 am, edited 2 times in total.
i cnat believe how bad im screwing this up
Its looping the 1st line in the text file the entire time before making a new CELL in the table.
Code: Select all
<?php
$filename = 'websuppliers.txt';
$fp = fopen( $filename, 'r' );
$file_contents = fread( $fp, filesize( $filename ) );
fclose( $fp );
$lines = explode ( "\n", $file_contents );
foreach ($lines as $line) {
list( $member, $city, $state ) = explode( '|', $line );
$member = trim($member);
$city = trim($city);
$state = trim($state);
print("<table><tr><td>");
$linecount=count(file("$filename"));
$halfcount=$linecount/2;
$currentcount=0;
while($currentcount<$halfcount){
print("
<table width="250" border="1" cellspacing="1" cellpadding="2" bordercolor="#000000" align="center">
<tr>
<td>
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#ffffff"><font color="#993300" face="Verdana" size="1"><b>$member  </b></font></td>
</tr>
</table>
</td>
</tr>
</table>
");
$currentcount++;
}
print("</td><td>");
// this is the column 2
while($currentcount>$halfcount && $currentcount<$count){
print("
<td valign="top">
<table width="250" border="1" cellspacing="1" cellpadding="2" bordercolor="#000000" align="center">
<tr>
<td>
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#ffffff"><font color="#993300" face="Verdana" size="1"><b>$member  </b></font></td>
</tr>
</table>
</td>
</tr>
</table>
");
$currentcount++;
}
}//end foreach
print("</td></tr></table><br><br>\n");
?>Code: Select all
$file=file($filename);
$file=array_chunk($file,(int)(count($file)/2));
$res=array();
foreach($file[0] as $key=>$line){
$res[$key][0]=$line;
$res[$key][1]=@$file[1][$key];
}