Jump to content

Archived

This topic is now archived and is closed to further replies.

olebrum

Need help with delimit a text file to a table

Recommended Posts

Hi, this is my first post (just wanted you to know)!

I have a "small" problem. I got a text file with results that i want to delimit and put into a table. The text generated to a file is:
$name|$score|$date

in a text file called, liste.txt, it will be like this:
Ole Lasse Johansen|10|10-08-2006 13:54:40

I want this text to be in a table:
[table]
  [tr]
    [td]Navn[/td]
    [td]Poeng (x av 10)[/td]
    [td]Dato[/td]
  [/tr]
  [tr]
    [td]Ole Lasse Johansen[/td]
    [td]10[/td]
    [td]10-08-2006 13:54:40[/td]
  [/tr]
[/table]

I wrote this script, but can't get it to work, how can i get it to work??

[code]<HTML>
<HEAD>
  <TITLE>Spill: Desimal, Binær og Heksadesimal tall</TITLE>
</HEAD>
<BODY>

<FONT SIZE="4">Spill: Desimal, Binær og Heksadesimal tall</FONT><BR><BR>

<?php

$liste = "./liste.txt";
if(!($fp = fopen($liste, "r"))) die ("Kan ikke åpne $liste.");
$innhold = fread($fp);
fclose($fp);

$delimiter = "|";
$splitinnhold = explode($delimiter, $innhold);
$teller = "";

?>

<TABLE WIDTH="80%" BORDER="1">
  <TR>
    <TD>Navn</TD>
    <TD>Poeng (x av 10)</TD>
    <TD>Dato</TD>
  </TR>

<?php

foreach ($splitinnhold as $text)
{
  $kolonne=0;
  $kolonner=3;

  echo "  <TR>\n";
 
  while($kolonne < $kolonner)
  {
    echo $text;
    $kolonne++;
    $counter++;
  }
  echo "  </TR>\n";
}

?>

</TABLE>

</BODY>
</HTML>[/code]

Share this post


Link to post
Share on other sites
You've forgotten the table cell tags in your while loop.
[code]
while($kolonne < $kolonner)
  {
    echo "<td>" . $text . "</td>";
    $kolonne++;
    $counter++;
  }
[/code]

Share this post


Link to post
Share on other sites
yes that's true, but it still doesn't work... I'll attach both liste.txt and liste.php so you can try for yourself.. I just can't figure it out...

[attachment deleted by admin]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.