Page 1 of 1

Extract data from .txt file

Posted: Mon Dec 15, 2008 9:31 pm
by dtwebdesign
Hello,

I would greatly appreciate help with the following!

I need a PHP function that can extract data from a plain .txt file (separated into rows and columns) into individual variables or arrays.

For reference, see this file: http://www.ndbc.noaa.gov/data/realtime2/41002.txt

For example, assign the data value in row 3 column 4 as $WSPD['4']

Is there any easy way to do this? Ultimately, I'd like to extract the data from files similar to the above and insert it into a MySQL database.

Any help or hints would be greatly appreciated!!!!!

-Dustin

Re: Extract data from .txt file

Posted: Mon Dec 15, 2008 9:44 pm
by cavemaneca
Look At This
Just read each line into an variable, explode into an array, store to database, lather, rinse, repeat.

Re: Extract data from .txt file

Posted: Mon Dec 15, 2008 10:14 pm
by dtwebdesign
Brilliant. I new it was easy.

It's funny and scary to think actually, that a huge website is based entirely on a workaround to not being able to solve this simple problem which you just helped me solve in I think less than an hour.

Thank you!