Extract data from .txt file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dtwebdesign
Forum Newbie
Posts: 2
Joined: Mon Dec 15, 2008 9:24 pm

Extract data from .txt file

Post 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
cavemaneca
Forum Commoner
Posts: 59
Joined: Sat Dec 13, 2008 2:16 am

Re: Extract data from .txt file

Post by cavemaneca »

Look At This
Just read each line into an variable, explode into an array, store to database, lather, rinse, repeat.
dtwebdesign
Forum Newbie
Posts: 2
Joined: Mon Dec 15, 2008 9:24 pm

Re: Extract data from .txt file

Post 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!
Post Reply