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
https://forums.phpfreaks.com/topic/5428-simple-php-request/
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
https://forums.phpfreaks.com/topic/5428-simple-php-request/#findComment-19535
Share on other sites

Archived

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

×
×
  • 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.