Jump to content


simple php request

  • Please log in to reply
3 replies to this topic

#1 petekin74

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 21 March 2006 - 04:43 PM

Hello. I have only just begon using php and I was hoping somebody could help me out with a quick script.

I have a text file [a href=\"http://www.ateamclan.com/test.txt\" target=\"_blank\"]http://www.ateamclan.com/test.txt[/a]

It has 3 columns that are tab delimited. I was looking for a script that would read this file and create a html table out of it. Each line would be a row in the table and each tab delimited field being its own cell. As more entries are added, I would need it to create more rows.

Any help would be appreciated.

#2 hitman6003

  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 22 March 2006 - 01:35 AM

Research the file and explode functions.

[a href=\"http://www.php.net/file\" target=\"_blank\"]http://www.php.net/file[/a]
[a href=\"http://www.php.net/explode\" target=\"_blank\"]http://www.php.net/explode[/a]

Also, make sure you understand foreach loops.

[a href=\"http://www.php.net/foreach\" target=\"_blank\"]http://www.php.net/foreach[/a].

$file = file("test.txt");
echo "<table>";
foreach ($file as $line) {
  $line = explode("\t",$line); //\t is a tab character.  \n would be a newline character
  echo "<tr><td>$line[0]</td><td>$line[1]</td><td>$line[2]</td></tr>";
echo "</table>";

I haven't looked at your file, but from what you said that should do what you want.

#3 kenrbnsn

  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 22 March 2006 - 01:42 AM

You should also look at the function [a href=\"http://www.php.net/fgetcsv\" target=\"_blank\"]fgetcsv[/a](). This will automagically parse the fields into an array which you can then use.


#4 petekin74

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 March 2006 - 11:23 PM

thanks guys, worked great

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users