processing text file for variables

:-\ I have a text file that I would like to load into a mysql db using PHP5. I would like to load it into the corresponding fields (Lat, Lon), I have done this with a csv but this format is way different and some help would be greatly appreciated. (The Locations are randomized for privacy)
Its format is:

Latitude: 34.300259376876
Longitude: -84.528306945041
Latitude: 34.7800316080451
Longitude: -84.354148024157
Latitude: 34.23373326080538
Longitude: --88.341622944251

well, u need to format the file before u can insert it.

i would go like this:

  1. load the whole csv in a variable example:
    [php]$csv = ‘Latitude: 34.300259376876
    Longitude: -84.528306945041
    Latitude: 34.7800316080451
    Longitude: -84.354148024157
    Latitude: 34.23373326080538
    Longitude: -88.341622944251’;[/php]

  2. explode the var by a new row delimiter to get the array:

[php]$csv =explode("\n", $csv);[/php]

3 go trough each field of an array and do something usefull

[php]for ($i= 0; $i< count($csv); $i++) {
//if first is longitude that means long is $csv[0] and coresponding lat is $csv[1]
//to echo each pair do this:
echo $csv[0+$i].’ - ‘.$csv[1+$i].’
’;
//in each circle of a loop two new pairs will be echoed.
}[/php]

since this is general help forum, not beginners u should know what how to goo from here.

Sponsor our Newsletter | Privacy Policy | Terms of Service