Help please!
I've been trying to get this function to work
I found this at;
http://www.zend.com/codex.php?id=964&single=1
It's a function that takes a file and converts it to an HTML table. After copying and pasting the function from my browser to Dreamweaver MX, I kept getting errors like "Parse error: parse error, unexpected T_VARIABLE in /Users/kenlin/Sites/TMPq4lou104zr.php on line 16
"
After meticulously deleting extra spaces from the code, it finally worked-- no errors.
Now when I try to execute the code, Ok, so I tried that, and at least I get some output, but now I get a HUGE bunch of numbers. Basically it is reading the txt file (comma separated text) and spitting out all the words except for the commas...
Any ideas?? (BTW, is there an easier way to get the code into Dreamweaver without having to do all the manual work of removing spaces and things from the code?)
I used this code:
<head>
<?php require("tableken2.php"); ?>
</head>
<body>Results
<? file2table ("aug21b.txt","geotable",",","lightyellow","lightgreen");?></body>
to call the file2table fucntion where tableken2.php contains the following code:
<?php
$x=0;
function file2table ($filename, $tablename, $delimiter, $r_color1, $r_color2)
{$x++;
$border=0;
$cellspacing=4;
$thColor="aqua";
$align="center";
$rowctr=0;
// change to 1 if you do not want table headers
$result="<div id=\table_$x\">\n\t";
$result.="<table border=\"$border\" cellspacing=\"$cellspacing\" align=\"$align\">\n\t\t";
//$file="info/contracts_warranties.txt";
$file="$filename";
$fd=@fopen($file,"r");
while(!feof($fd))
{$rowctr++;
$buffer=fgets($fd,filesize($file) );
$line=explode($delimiter,rtrim($buffer) );
//$arrylgth = count($line);
if ($rowctr==1)
{
$result.="<tr>\n\t\t\t";
$arrylgth=count($line);
for($colctr=0;$colctr<$arrylgth;$colctr++)
{
$result.="<th bgColor=\"$thColor\" nowrap><font size=\"+1\">$line[$colctr]</font></th>\n\t\t\t";
}
$result.="\n\t\t</tr>";
$columns=$arrylgth;
}
else
{
$result.="<tr>\n\t\t\t";
$altcolor++;
for($colctr=0;$colctr<$columns;$colctr++)
{
if($line[$colctr]==""){$line[$colctr]=" ";}
if($altcolor%2==0)
{
$result.="<td bgColor=\"$r_color1\">$line[$colctr]</td>\n\t\t\t";
}
else
{
$result.="<td bgColor=\"$r_color2\">$line[$colctr]</td>\n\t\t\t";
}
}
$result.="\n\t\t</tr>";
}
}
$result.="\n\t</table?\n\t</div>\n";
fclose($fd);
print $result
}
?>
The Text file:
http://ripperz.dns2go.com/aug21b.txt
What the table is supposed to look like:
http://ripperz.dns2go.com/phptest/file-to-table.php
THANKS