Forum Moderators: coopster

Message Too Old, No Replies

Tab delimited txt file to php html table

Trying to use a tutorial to convert text to html, but it isn't working

         

jamesrskemp

1:56 am on May 26, 2005 (gmt 0)

10+ Year Member



Wouldn't you know that when I finally find a tutorial using Google that does exactly what I want, the code doesn't run when I use it ...

However, when it gets to this line, for ($i=0; $i<td>$line[0]</td>, it chokes on one of the '>'.

Since my php skills are very basic, and in no way include arrays, can someone assist me with this?

If it's easier to do it differently, what I'd like to do is create a table in Excel/Access, export it to the server (to a tab-delimted text file, since I'll be using commas in my table cells), and have it display in an HTML table.

If I can't figure this out, I'm tempted to just export to HTML from one or the other program (not sure quite yet which I would use), so ...

Any help would be greatly appreciated - either filling in the missing code for the tutorial linked to above, or directing me to another tutorial that discusses this (lots from HTML to txt/csv), or otherwise.

Thanks :)

~James

[edited by: jatar_k at 2:12 am (utc) on May 26, 2005]
[edit reason] sorry no urls thanks [/edit]

jatar_k

2:18 am on May 26, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



actually you could use a comma delimited file even with commas in your fields. The enclosure could be double quotes, as is most often the default, and then it knows which commas are between fields and which ones are within fields.

fgetcsv [php.net] is the function you want, you can set the delimiter to a tab if you like, I believe that is "\t" not sure though, must ahve double quotes aroun it though. '\t' just reads as slash t to php as it is unparsed between single quotes.

You could use fgetcsv to read the data from the file, which pulls it into an array fpr you, in the order in which they exist in the file. Then put the values into an insert query and you're off to the races.

jamesrskemp

3:23 am on May 26, 2005 (gmt 0)

10+ Year Member



Thanks jatar_k, that gives me a place to look ...

Since CSV will work, I'll try a couple of searches on Google as well (since I was looking for tab-delimited in my first 5 rounds).

jatar_k

3:30 am on May 26, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the steps would be as follows

1. export and copy your source file to the server
2. use fopen to open a file pointer to your file
3. use fgetcsv to read the next line into an array
4. use that array to construct your INSERT query
5. execute your INSERT query
6. repeat lines 3,4,5 in a loop until you reach the end of file
7. finished