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
)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…