jeffry s wrote: > i have text file and a table created with > > create table word( > id int not null auto_increment primary key, > word varchar(50), > definition text > ) > > the text contain list of words but not really in specific format > > word, some text definition > word, some text definition, some text definition, etc > > > i want to read the file line by line, > take the first word before comma (,) and insert into the word column in the > database > whatever after follow the first comma(,) will be inserted into the > definition column in the word table database. > > i am not sure how to read the file line by line in php. > and how to separate the line of text into two. divided by the 1st comma (,) > .. > my idea is using the explode(',' $text) function. but this one will separate > everything between a comma(,) into an array. > i wan't to know if there is another better way to do it.. > > > any idea? > thank you! > Read about the file() function and also read about the explode() function's limit parameter. -Shawn if(($lines = file("file.txt"))) { foreach($lines as $line) { list($word, $definition) = explode($line, ',', 1); //insert word and definition SQL stuff here } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php