Jump to content

simple php request


petekin74

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.