petekin74 Posted March 21, 2006 Share Posted March 21, 2006 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 Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 22, 2006 Share Posted March 22, 2006 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. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 22, 2006 Share Posted March 22, 2006 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.Ken Quote Link to comment Share on other sites More sharing options...
petekin74 Posted March 23, 2006 Author Share Posted March 23, 2006 thanks guys, worked great Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.