Page 1 of 1

Creating a HTML log -- closing the table and html tag

Posted: Sat Jul 21, 2007 10:10 am
by LonelyProgrammer
Hi all,

I am currently doing a HTML log of daily transactions of an e-commerce website. I have to add transactions as a row to a table. Now I am stuck on how I do insert into the middle of the log file, just before the the closing </table></html> tag.

I was thinking of truncating the file to remove the closing tags, then continue to append to it. But there isn't any function that gives me back the size of a string, so I don't know the amount of offset for ftruncate().

PS. I know that actually without the closing tags, the html file will still show, but the perfectionist in me won't give up. :)

Posted: Sat Jul 21, 2007 10:30 am
by superdezign
I'd highly suggest that you do your logging through the database (or through a plain-text file, if you must), and then write a script to display the data as a table.

Posted: Sat Jul 21, 2007 10:43 am
by feyd
Is there a reason you're not using a database/flat-file as the back-end source for this information?

Posted: Sat Jul 21, 2007 10:50 am
by LonelyProgrammer
There is a database back-end, but the client is requesting one which he can just donwload from the FTP server. I have shown him how to export the backend tables as excel, but apparently not good enough for his purpose.

Also, there are some other transactions info which are not stored in the DB but he wants in the HTML log. I could just add that to the DB though, but as the operation is live already, I don't want to add existing empty fields to the tables.

Posted: Sat Jul 21, 2007 11:44 am
by superdezign
Log it regularly, and THEN translate it into HTML tables. Logs should be simplistic, but you can display them however you like.

Posted: Sun Jul 22, 2007 9:40 pm
by Phoenixheart
I would suggest this (dirty) way:
- First, you can read the whole log file into a string using file_get_contents().
- Find the position of </table> using strpos.
- Now that you have the position. Do whatever you like (As I remember we have some file system functions)
Hope this would help :D