does anybody has an idea of parsing the filename of the textfile and its contents and insert to database…
example…
format of the filename:
[date]
[time]
201089 1-111 93300.txt
contents of the text file:
12345 John Robinson
54321 Robert svenson
the table where the information should be inserted has this
fields.. name of table: logs
[ID] [name] [date]
[time]
say for example the parsing is done…it should look like this.
[ID] [name] [date]
[time]
12345 John Robinson 2010-8-9 1-111 9:33:00
54321 Robert Svenson 2010-8-9 1-111 9:33:000
how can i do that??
can somebody help me?
thanks.
Since you will have several entries in in your file you will need to explode by
(newline) and use the 1st array example
Here you will need another loop (inside the readdir loop) http://www.php.net/manual/en/control-structures.foreach.php
Where you will do yet another explode by space and again, I would use the 2nd list example. Don’t forget the first and last name are separated by a space.
Here is where you would write to the database.
You have the first [date]
[time] values from the first explode by space then here you would have [ID] [name] from the last explode by space.
Since the first explode is outside of the /n explode those values will stay the same and on the next loop it will get the next [ID] [name] values.
If you are new to PHP and sounds like you want to learn, this will give you the planning and the links provided will pretty much build it for you.
Cheers
Loren