UG1234 Posted January 24, 2010 Share Posted January 24, 2010 Hi, i am new to PHP and i am struggling with importing data from a CSV file. Basicly i am creating a map and trying to draw a shape on it and i am pulling the coordinates to plot the shape from a CSV file. My test.csv file consists of 3 set of coordinates and looks like this; 337339, 403450 354810, 433189 224600, 689900 i would like to pull in each line to fill variables p1, p2 and p3. Below is my first attempt of this var p1 = new OpenLayers.Geometry.Point( <?PHP $file_handle = fopen("test.csv"="r"); $line_of_text = fgetcsv($file_handle, 1024); print $line_of_text[0] . $line_of_text[1]. "<BR>"; } fclose($file_handle); ?> ); var p2 = new OpenLayers.Geometry.Point( <?PHP $file_handle = fopen("test.csv"="r"); $line_of_text = fgetcsv($file_handle, 1024); print $line_of_text[2] . $line_of_text[3]. "<BR>"; } fclose($file_handle); ?> ); var p3 = new OpenLayers.Geometry.Point( <?PHP $file_handle = fopen("test.csv"="r"); $line_of_text = fgetcsv($file_handle, 1024); print $line_of_text[4] . $line_of_text[5]. "<BR>"; } fclose($file_handle); ?> ); Thanks for any help in advance Link to comment https://forums.phpfreaks.com/topic/189635-extracting-data-from-csv-file/ Share on other sites More sharing options...
jl5501 Posted January 24, 2010 Share Posted January 24, 2010 The first issue I see is the fact that you are opening and closing the file each time and each time you open, you will read the same line. The second issue I see is that you expect the array index to have advanced each time, when in fact, as you have 2 values on each line, then it will use indeces [0] and [1] for each line read Link to comment https://forums.phpfreaks.com/topic/189635-extracting-data-from-csv-file/#findComment-1000877 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.