Jump to content


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


simple php request

Recommended Posts

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.

Share this post

Link to post
Share on other sites
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].

[code]$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>";[/code]

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

Share this post

Link to post
Share on other sites
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.


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.