如何从此CSV文件中获取特定列?

时间:2015-01-15 11:51:49

标签: php arrays csv multidimensional-array

如何从此CSV文件中获取所有纬度和经度值?

id   M3_id   name   adress   city              postcode   state   phone   email   url   brandstore   online   country_id   latitude                    longitude                   fax   season   filename   order   public
             bla    xxx      Biedermannsdorf   A-2362             458             www   0            0        15           4.808.707.420.000.000.000   1.635.738.590.000.000.000   4     SW                  0       1
             bla    xxx      y                 A-8053             456             www   0            0        15           470.106.506                 154.049.301                 5     SW                  0       1
     0       bla    xxx      y                 A-1200             5467            ww    0            0        15           482.283.707                 163.706.093                 8     SW                  0       1
             bla    xxxy     Linz              A-4020             665             www   0            0        15           483.092.194                 143.290.005                 7     S                   0       1
                                                                                  ww    1            1        15                                                                         SW       none       0       1
到目前为止

代码:但我可以找出从数组中获取坐标的下一步......

$filepath = "uploads/austria.csv"; 
    $file_handle = fopen($filepath, "r");

    $countRows = 0; 
     while (!feof($file_handle) ) {
        // get data using fgetcsv and push to an array
        $line_of_text[] = fgetcsv($file_handle, 1024);
        $countRows++; 
    }

    //Close the file after reading
    fclose($file_handle);

    print "<pre>"; 
    print_r($line_of_text);
    print "</pre><b>"; 


    function importDataFromCvsFile($fileName, $delimiter = ',') {
        $result = array();
        if (($handle = fopen($fileName, "r")) !== FALSE) {
            while (($data = fgetcsv($handle, 2000, $delimiter)) !== FALSE) {
                $result[] = $data;
            }
            fclose($handle);
        } else {
            return false;
        }
        return $result;
    }

0 个答案:

没有答案