I have this array with airport codes and city names (around 3500 lines).
code,city
"Abilene, TX ",ABI
"Adak Island, AK ",ADK
"Akiachak, AK ",KKI
"Akiak, AK ",AKI
"Akron/Canton, OH ",CAK
"Akuton, AK ",KQA
"Alakanuk, AK ",AUK
"Alamogordo, NM ",ALM
I need to convert that file into a php array. This is my code so far:
if(($handle = fopen('test.csv', 'r')) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ',', '"')) !== FALSE) {
echo '<pre>';
print_r($data);
echo '</pre>';
}
fclose($handle);
}
Although I'm setting the delimiter and enclousure characters for the fgetcsv function, im getting this as a result:
Array
(
[0] => code
[1] => city
"Abilene
[2] => TX "
[3] => ABI
"Adak Island
[4] => AK "
[5] => ADK
"Akiachak
[6] => AK "
[7] => KKI
"Akiak
[8] => AK "
[9] => AKI
"Akron/Canton
[10] => OH "
[11] => CAK
"Akuton
[12] => AK "
[13] => KQA
"Alakanuk
[14] => AK "
[15] => AUK
"Alamogordo
[16] => NM "
[17] => ALM
)
"chars and not the fancy 66's and 99's that MS loves to sprinkle everywhere?PHP_VERSION. (Which is it?) Alternatively tryvar_dump(array_map("str_getcsv", file($fn))).auto_detect_line_endings1is just the result ofprint_r()which gets written out by theechoafter print_r itself already threw its output out. (Why it's also not within the pre tags.)