Current location: Hot Scripts Forums » Programming Languages » PHP » Displaying TEXT file contents to HTML tables


Displaying TEXT file contents to HTML tables

Reply
  #1 (permalink)  
Old 02-15-04, 02:40 PM
Mendo Mendo is offline
New Member
 
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Displaying TEXT file contents to HTML tables

I have a php script that writes inputed info to a text file, adding new lines each time, so the write to file looks this:

fwrite($text_file, "$example|$catagory||\n");

and the text file contents would be like this:

testing|test one||
test|test two||

So the thing I'm trying to ask is, how would I get the contents in the text file to be displayed in an html table, so it would sort of look like this:

<table><tr><td>
testing
</td><td>
test one
</td></tr>
<tr><td>
test
</td><td>
test two
</td></tr></table>

Also, does php have a function that would allow the lines in the text file to be displayed in the html tables alphabetically?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 02-18-04, 11:50 AM
Mendo Mendo is offline
New Member
 
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
I think I might have posted in wrong section.. maybe this was more for Script Request?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 02-18-04, 12:19 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
Quote:
Originally Posted by Mendo
I think I might have posted in wrong section.. maybe this was more for Script Request?
no this is the right place..
to do this, you need to use file();
read each line and explode it and then echo it..
PHP Code:

//first, get the file...

$file file('file.txt');

//now count the lines ..
$lines count($file);

//start the table here..
echo'<table border="0" width="100%">';

//start the loop to get all lines in the table..
for ($i=0$i<=$lines$i++) {

//get each line and exlplode it..
  
$part explode('|'$file[$i]);
//now start printing ..
  
echo'<tr>
              <td width="50%">'
.$part[0].'</td>
              <td width="50%">'
.$part[1].'</td>
         </tr>'
;
}

//close the table so HTML wont suffer :P
echo'</table>'
I highly suggest that you don't close your line with double || , just leave them blank ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]

Last edited by NeverMind; 02-18-04 at 12:23 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
change the contents of an html file in asp jaleen ASP 4 01-21-04 08:41 AM
change the contents of an html file in asp jaleen Script Requests 0 12-30-03 02:53 PM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 05:28 PM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 08:19 PM
Editing a text file. cjh_60 PHP 1 10-14-03 04:59 PM


All times are GMT -5. The time now is 09:13 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.