Home > Archive > PHP SQL > August 2004 > parse text file into database
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
parse text file into database
|
|
| friedcpu 2004-08-18, 3:57 pm |
| Hi
I really dont know where to start, so if you could point me in the
right direction, tutorial or actual script it would help so much :)
I need something that will read every line of a text file
read the text before the * and after the start, then put it in a table
in the database
ie: read question*answer
put to database
ID QUESTION ANSWER
thank you so much if you can help :)
- Will
----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums
| |
| Barand 2004-08-18, 3:57 pm |
| > PERL is your friend here.
>
>
This is a PHP site :blink:
To read the file into an array, use file() function.
You can the process each line, splitting at the * like this
--------
data = file('myfile.txt');
foreach (data as line) {
_ _list (q, a) = explode('*' ,
trim(line) );
_ _mysql_query("INSERT INTO mytable (question,
answer) VALUES ('q',
'a')";
}
--------
Make the ID field auto_increment.
hth
Barand
http://members.aol.com/barryaandrew...agridguide.html easy
data tables - and more
----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums
|
|
|
|
|