drisate Posted September 16, 2008 Share Posted September 16, 2008 Hey guys i have a string that looks like this -Albania LATI -> Tirana + -Angola FNLU -> Luanda + -Antarctic NZCM -> Williams Field + -Antigua and Barbuda TAPA -> Vc Bird International Airport Antigua + -Algeria DAUA -> Adrar DABB -> Annaba DABC -> Constantine DAAG -> Dar-El-Beida DAUG -> Ghardaia DAUH -> Hassi-Messaoud DAUZ -> In Amenas DAOO -> Oran / Es Senia DAAT -> Tamanrasset / Aguenna DABS -> Tebessa DAON -> Tlemcen Zenata + -Argentina SABE -> Aeroparque Bs. As. Aerodrome SAZB -> Bahia Blanca Aerodrome SAZS -> Bariloche Aerodrome SAVC -> Comodoro Rivadavia Aerodrome SAAC -> Concordia Aerodrome SACO -> Cordoba Aerodrome SARC -> Corrientes Aero. SADD -> Don Torcuato Aerodrome SAEZ -> Ezeiza Aerodrome SARF -> Formosa Aerodrome SARI -> Iguazu Aerodrome SASJ -> Jujuy Aerodrome SAZM -> Mar Del Plata Aerodrome SAME -> Mendoza Aerodrome SAZN -> Neuquen Aerodrome SARL -> Paso De Los Libres Aerodrome SARP -> Posadas Aero. SARE -> Resistencia Aero. SAWG -> Rio Gallegos Aerodrome SAWE -> Rio Grande B. A. SAAR -> Rosario Aerodrome SASA -> Salta Aerodrome SANU -> San Juan Aerodrome SANE -> Santiago Del Estero Aero. SAAV -> Sauce Viejo Aerodrome SAVT -> Trelew Aerodrome SANT -> Tucuman Aerodrome SAOR -> Villa Reynolds Aerodrome + -Armenia UGEE -> Yerevan + -Aruba TNCA -> Queen Beatrix Airport, Aruba + -Australia YPAD -> Adelaide Airport YBAS -> Alice Springs Aerodrome YPPH -> Belmont Perth Airport YBBN -> Brisbane Airport M. O YBRM -> Broome Airport YPEA -> Bullsbrook Pearce Amo YBCS -> Cairns Airport YSCB -> Canberra YPDN -> Darwin Airport YSDU -> Dubbo YMHB -> Hobart Airport YPTN -> Katherine Aerodrome YPLM -> Learmonth Airport YMML -> Melbourne Airport YSNF -> Norfolk Island Airport YPPD -> Port Hedland Pardoo YSRI -> Richmond Aus-Afb YBRK -> Rockhampton Airport YSSY -> Sydney Airport YBTL -> Townsville Amo + -Austria LOWG -> Graz-Thalerhof-Flughafen LOWI -> Innsbruck-Flughafen LOWK -> Klagenfurt-Flughafen LOWL -> Linz / Hoersching-Flughafen LOWS -> Salzburg-Flughafen LOWW -> Wien / Schwechat-Flughafen + -Azerbaijan UBBB -> Baku / Bine Airport + -Bahamas MYGF -> Freeport, Grand Bahama MYNN -> Nassau Airport + -Bahrain OBBI -> Bahrain International Airport + -Bangladesh VGEG -> Chittagong Patenga VGZR -> Kurmitola, Dia + -Barbados TBPB -> Grantley Adams + -Belarus UMMS -> Minsk EVRA -> Riga Airport UMII -> Vitebsk + -Belgium EBAW -> Antwerpen / Deurne EBBE -> Beauvechain EBLG -> Bierset EBBT -> Brasschaat EBBR -> Bruxelles National EBCI -> Charleroi / Gosselies EBCV -> Chievres EBLB -> Elsenborn EBFS -> Florennes EBTN -> Goetsenhoven EBBL -> Kleine Brogel EBFN -> Koksijde EBOS -> Oostende Airport EBDT -> Schaffen EBSP -> Spa / La Sauveniere + -Belize MZBZ -> Belize / Phillip Goldston Intl. Airport + -Benin DBBB -> Cotonou + -Bermuda TXKF -> Bermuda + -Bolivia SLCA -> Camiri SLCN -> Charana SLCO -> Cobija SLCB -> Cochabamba SLCP -> Concepcion SLLP -> La Paz / Alto SLMG -> Magdalena SLOR -> Oruro SLPO -> Potosi SLPS -> Puerto Suarez SLRY -> Reyes SLRI -> Riberalta SLRB -> Robore SLRQ -> Rurrenabaque SLSI -> San Ignacio De Velasco SLJO -> San Joaquin SLJE -> San Jose De Chiquitos SLSA -> Santa Ana SLSU -> Sucre SLTJ -> Tarija SLTR -> Trinidad SLVM -> Villamontes SLVR -> Viru-Viru SLYA -> Yacuiba + -Botswana FBFT -> Francistown FBGZ -> Ghanzi FBJW -> Jwaneng FBKE -> Kasane FBMN -> Maun FBSK -> Seretse Khama International Airport FBSW -> Shakawe FBTS -> Tsabong FBTE -> Tshane + -Brazil SBAF -> Afonsos Aeroporto SBAT -> Alta Floresta Aeroporto SBHT -> Altamira SBAR -> Aracaju Aeroporto SBBG -> Bage Aeroporto SBBU -> Bauru SBBE -> Belem Aeroporto SBCF -> Belo Horizonte SBBH -> Belo Horizonte Aeroporto SBBV -> Boa Vista Aeropor-To SBBR -> Brasilia Aeroporto SBKG -> Campina Grande SBKP -> Campinas Aeroporto SBCG -> Campo Grande Aeroporto SBCV -> Caravelas Aeropor-To SBAA -> Conceicao Do Araguaia SBCR -> Corumba SBCY -> Cuiaba Aeroporto SBBI -> Curitiba SBCT -> Curitiba Aeroporto SBEG -> Eduardo Gomes International SBFN -> Fernando De Noronha SBFL -> Florianopolis Aeroporto SBFZ -> Fortaleza Aeropor-To SBFI -> Foz Do Iguacu Aeroporto SBGL -> Galeao SBGO -> Goiania Aeroporto SBGW -> Guaratingueta SBGR -> Guarulhos Civ / Mil SBIL -> Ilheus Aeroporto SBIZ -> Imperatriz SBIH -> Itaituba SBLO -> Londrina Aeroporto SBME -> Macae SBMQ -> Macapa SBMO -> Maceio Aeroporto SBMN -> Manaus Aeroporto SBMA -> Maraba SBMT -> Marte Civ / Mil SBNT -> Natal Aeroporto SBPK -> Pelotas SBYS -> Pirassununga SBPC -> Pocos De Caldas SBPP -> Ponta Pora Aeropor-To SBCO -> Porto Alegre SBPA -> Porto Alegre Aero-Porto SBPN -> Porto Nacional Aeroporto SBPV -> Porto Velho Aeroporto SBDN -> Presidente Prudente SBRF -> Recife Aeroporto SBJR -> Rio / Jacarepagua SBRB -> Rio Branco SBRJ -> Rio De Janeiro Aeroporto SBSV -> Salvador Aeroporto SBSC -> Santa Cruz Aeropor-To SBSM -> Santa Maria Aero-Porto SBSN -> Santarem-Aeroporto SBST -> Santos Aeroporto SBSJ -> Sao Jose Dos Campo SBSL -> Sao Luiz Aeroporto SBSP -> Sao Paulo Aeropor-To SBTT -> Tabatinga SBTF -> Tefe SBTE -> Teresina Aeroporto SBTU -> Tucurui SBUR -> Uberaba SBUG -> Uruguaiana Aeroporto SBVH -> Vilhena Aeroporto SBVT -> Vitoria Aeroporto + -British Indian Ocean Territory FJDG -> Diego Garcia + -Brunei Darussalam WBSB -> Brunei Airport + -Bulgaria LBBG -> Burgas LBPD -> Plovdiv LBSF -> Sofia Observ. LBWN -> Varna + -Burundi HBBA -> Bujumbura + -Cambodia VDPP -> Phnom-Penh / Pochentong + -Cameroon FKKD -> Douala Obs. + -Canada CYXX -> Abbotsford, B. C. CYBG -> Bagotville, Que. CYYC -> Calgary International, Alta. CYCB -> Cambridge Bay, N. W. T. CYCH -> Chatham Can-Mil CZUM -> Churchill Falls, Nfld. CYYQ -> Churchill, Man. CYOD -> Cold Lake, Alta. CYQQ -> Comox, B. C. CYZS -> Coral Harbour, N. W. T. CYEG -> Edmonton International, Alta. CYET -> Edson, Alta. CZFM -> Fort Mcpherson Airport CYFC -> Fredericton, N. B. CYQX -> Gander Int. Airport, Nfld. CYYR -> Goose, Nfld. CYZX -> Greenwood, N. S. CYHZ -> Halifax International Airport CYFB -> Iqaluit, N. W. T. CYAH -> La Grande Iv, Que. CYGL -> La Grande Riviere, Que CYZY -> Mackenzie, B. C. CYNM -> Matagami, Que. CYXH -> Medicine Hat, Alta. CYQM -> Moncton, N. B. CYUL -> Montreal / Dorval International, Que CYMX -> Montreal / Mirabel CYBU -> Nipawin, Sask. CYOC -> Old Crow Airport CYOW -> Ottawa Int'L. Ont. CYYF -> Penticton, B. C. CYZT -> Port Hardy, B. C. CYPG -> Portage Southport A CYQB -> Quebec, Que CYUY -> Rouyn Airport CWZZ -> Saglek Bay CYAY -> Saint Anthony Airport CYZV -> Sept-Iles, Que. CYAW -> Shearwater, N. S. CYUA -> Shingle Point, Y. T. CYYT -> St. John's, Nfld CYJT -> Stephenville, Nfld. CYYN -> Swift Current, Sask. CYQY -> Sydney, N. S. CYTH -> Thompson Weather Office, Man CYYZ -> Toronto Pearson Int'L. Ont. CYTR -> Trenton, Ont. CYVR -> Vancouver International Air-Port, B. C. CYYJ -> Victoria Int. Airportb. C. CYQG -> Windsor, Ont. CYWG -> Winnipeg Int. Airportman. CYZF -> Yellowknife, N. W. T. + -Cape Verde GVAC -> Sal + -Cayman Islands MWCR -> Owen Roberts Airportgrand Cayman + -Central African Republic FEFF -> Bangui + -Chad FTTJ -> Ndjamena + -Chile SCFA -> Antofagasta SCAR -> Arica SCIE -> Concepcion SCHA -> Copiapo SCDA -> Iquique / Diego Arac SCIP -> Isla De Pascua SCSE -> La Serena SCEL -> Pudahuel SCTE -> Puerto Montt SCCI -> Punta Arenas + -China ZBAA -> Beijing ZUUU -> Chengdu ZYTL -> Dalian ZGGG -> Guangzhou ZSHC -> Hangzhou ZSOF -> Hefei ZPPP -> Kunming ZGNN -> Nanning ZSSS -> Shanghai / Hongqiao ZGSZ -> Shenzhen ZBYN -> Taiyuan ZBTJ -> Tianjin / Zhangguizhu ZWWW -> Urum-Qi / Diwopu ZSAM -> Xiamen + -Christmas Island YPXM -> Christmas Island Aerodrome YPCC -> Cocos Island Airport + -Colombia SKBQ -> Barranquilla / Ernestocortissoz SKBO -> Bogota / Eldorado SKBG -> Bucaramanga / Palonegro SKCL -> Cali / Alfonso Bonillaaragon SKCG -> Cartagena / Rafael Nunez SKLT -> Leticia / Vasquez Cobo SKMD -> Medellin / Olaya Herrera SKPE -> Pereira / Matecana SKRG -> Rionegro / J. M. Cordova SKSP -> San Andres Isla / Sesquicentenario SKSM -> Santa Marta / Simon Bolivar + -Comoros FMCZ -> Dzaoudzi / Pamanzi Mayotte FMCH -> Hahaya International Airport + -Congo FCBB -> Brazzaville / Maya-Maya FCPP -> Pointe-Noire + -Cook Islands NCRG -> Rarotonga + -Costa Rica MRCH -> Chacarita MROC -> Juan Santamaria MRLB -> Liberia MRLM -> Puerto Limon MRPV -> Tobias Bolanos International + -Cote D'Ivoire DIAP -> Abidjan + -Croatia LDDU -> Dubrovnik / Cilipi LDPL -> Pula Aerodrome LDRI -> Rijeka / Omisalj LDSP -> Split / Resnik LDZD -> Zadar / Zemunik LDZA -> Zagreb / Pleso + [...] I neet to extrac those values to put them in a DB For every $country i need the $code and $location I think the best way would be exploding the + then a preg_match? If thats the case, can you help my build the regex expression? If it's possible to do it all with regex it would be even better. Quote Link to comment Share on other sites More sharing options...
effigy Posted September 16, 2008 Share Posted September 16, 2008 What have you tried, or how would you start the expression? Quote Link to comment Share on other sites More sharing options...
drisate Posted September 16, 2008 Author Share Posted September 16, 2008 I was trying doing it with explodes and loops ... but my code was gething rediculous ... $row=explode('+', $string); foreach($row as $value){ $country=explode('\n', $value); $co=str_replace('-', '', $country[0]); $cut=explode('->', $country[1]); print ("$co = Country<br> $cut[0]= Code<br> $cut[1]= location"); } But this is obviously not gona work ... then i thought it would be best to use some regex This outputs: http://blessingstairs.org/code.php Quote Link to comment Share on other sites More sharing options...
drisate Posted September 16, 2008 Author Share Posted September 16, 2008 I managed to get this code working string = "-Albania LATI -> Tirana + -Angola FNLU -> Luanda + -Antarctic NZCM -> Williams Field + -Antigua and Barbuda TAPA -> Vc Bird International Airport Antigua + -Algeria DAUA -> Adrar DABB -> Annaba DABC -> Constantine DAAG -> Dar-El-Beida DAUG -> Ghardaia DAUH -> Hassi-Messaoud DAUZ -> In Amenas DAOO -> Oran / Es Senia DAAT -> Tamanrasset / Aguenna DABS -> Tebessa DAON -> Tlemcen Zenata + -Argentina SABE -> Aeroparque Bs. As. Aerodrome SAZB -> Bahia Blanca Aerodrome SAZS -> Bariloche Aerodrome SAVC -> Comodoro Rivadavia Aerodrome SAAC -> Concordia Aerodrome SACO -> Cordoba Aerodrome SARC -> Corrientes Aero. SADD -> Don Torcuato Aerodrome SAEZ -> Ezeiza Aerodrome SARF -> Formosa Aerodrome SARI -> Iguazu Aerodrome SASJ -> Jujuy Aerodrome SAZM -> Mar Del Plata Aerodrome SAME -> Mendoza Aerodrome SAZN -> Neuquen Aerodrome SARL -> Paso De Los Libres Aerodrome SARP -> Posadas Aero. SARE -> Resistencia Aero. SAWG -> Rio Gallegos Aerodrome SAWE -> Rio Grande B. A. SAAR -> Rosario Aerodrome SASA -> Salta Aerodrome SANU -> San Juan Aerodrome SANE -> Santiago Del Estero Aero. SAAV -> Sauce Viejo Aerodrome SAVT -> Trelew Aerodrome SANT -> Tucuman Aerodrome SAOR -> Villa Reynolds Aerodrome + -Armenia UGEE -> Yerevan + -Aruba TNCA -> Queen Beatrix Airport, Aruba + -Australia YPAD -> Adelaide Airport YBAS -> Alice Springs Aerodrome YPPH -> Belmont Perth Airport YBBN -> Brisbane Airport M. O YBRM -> Broome Airport YPEA -> Bullsbrook Pearce Amo YBCS -> Cairns Airport YSCB -> Canberra YPDN -> Darwin Airport YSDU -> Dubbo YMHB -> Hobart Airport YPTN -> Katherine Aerodrome YPLM -> Learmonth Airport YMML -> Melbourne Airport YSNF -> Norfolk Island Airport YPPD -> Port Hedland Pardoo YSRI -> Richmond Aus-Afb YBRK -> Rockhampton Airport YSSY -> Sydney Airport YBTL -> Townsville Amo + -Austria LOWG -> Graz-Thalerhof-Flughafen LOWI -> Innsbruck-Flughafen LOWK -> Klagenfurt-Flughafen LOWL -> Linz / Hoersching-Flughafen LOWS -> Salzburg-Flughafen LOWW -> Wien / Schwechat-Flughafen + -Azerbaijan UBBB -> Baku / Bine Airport + -Bahamas MYGF -> Freeport, Grand Bahama MYNN -> Nassau Airport + -Bahrain OBBI -> Bahrain International Airport + -Bangladesh VGEG -> Chittagong Patenga VGZR -> Kurmitola, Dia + -Barbados TBPB -> Grantley Adams + -Belarus UMMS -> Minsk EVRA -> Riga Airport UMII -> Vitebsk + -Belgium EBAW -> Antwerpen / Deurne EBBE -> Beauvechain EBLG -> Bierset EBBT -> Brasschaat EBBR -> Bruxelles National EBCI -> Charleroi / Gosselies EBCV -> Chievres EBLB -> Elsenborn EBFS -> Florennes EBTN -> Goetsenhoven EBBL -> Kleine Brogel EBFN -> Koksijde EBOS -> Oostende Airport EBDT -> Schaffen EBSP -> Spa / La Sauveniere + -Belize MZBZ -> Belize / Phillip Goldston Intl. Airport + -Benin DBBB -> Cotonou + -Bermuda TXKF -> Bermuda +"; $string=str_replace("\n", '*', str_replace("\r", '', $string)); $string=str_replace('* ', '*', $string); $string=str_replace(' * ', '*', $string); $string=str_replace('*+*', '%', $string); $string=str_replace('->', '&', $string); $string=str_replace(' & ', '&', $string); // The above outputs a string that looks like this in 1 line /*-Albania*LATI&Tirana%-Angola*FNLU&Luanda%-Antarctic*NZCM&Williams Field%-Antigua and Barbuda*TAPA&Vc Bird International Airport Antigua%-Algeria*DAUA&Adrar*DABB&Annaba*DABC&Constantine*DAAG&Dar-El-Beida*DAUG&Ghardaia*DAUH&Hassi-Messaoud*DAUZ&In Amenas*DAOO&Oran / Es Senia*DAAT&Tamanrasset / Aguenna*DABS&Tebessa*DAON&Tlemcen Zenata %-Argentina*SABE&Aeroparque Bs. As. Aerodrome*SAZB&Bahia Blanca Aerodrome*SAZS&Bariloche Aerodrome*SAVC&Comodoro Rivadavia Aerodrome*SAAC&Concordia Aerodrome*SACO&Cordoba Aerodrome*SARC&Corrientes Aero.*SADD&Don Torcuato Aerodrome*SAEZ&Ezeiza Aerodrome*SARF&Formosa Aerodrome*SARI&Iguazu Aerodrome*SASJ&Jujuy Aerodrome*SAZM&Mar Del Plata Aerodrome*SAME&Mendoza Aerodrome*SAZN&Neuquen Aerodrome*SARL&Paso De Los Libres Aerodrome*SARP&Posadas Aero.*SARE&Resistencia Aero.*SAWG&Rio Gallegos Aerodrome*SAWE&Rio Grande B. A.*SAAR&Rosario Aerodrome*SASA&Salta Aerodrome*SANU&San Juan Aerodrome*SANE&Santiago Del Estero Aero.*SAAV&Sauce Viejo Aerodrome*SAVT&Trelew Aerodrome*SANT&Tucuman Aerodrome*SAOR&Villa Reynolds Aerodrome%-Armenia*UGEE&Yerevan%-Aruba*TNCA&Queen Beatrix Airport, Aruba%-Australia*YPAD&Adelaide Airport*YBAS&Alice Springs Aerodrome*YPPH&Belmont Perth Airport *YBBN&Brisbane Airport M. O*YBRM&Broome Airport*YPEA&Bullsbrook Pearce Amo*YBCS&Cairns Airport*YSCB&Canberra*YPDN&Darwin Airport*YSDU&Dubbo*YMHB&Hobart Airport*YPTN&Katherine Aerodrome*YPLM&Learmonth Airport*YMML&Melbourne Airport*YSNF&Norfolk Island Airport*YPPD&Port Hedland Pardoo*YSRI&Richmond Aus-Afb *YBRK&Rockhampton Airport*YSSY&Sydney Airport*YBTL&Townsville Amo%-Austria*LOWG&Graz-Thalerhof-Flughafen*LOWI&Innsbruck-Flughafen*LOWK&Klagenfurt-Flughafen*LOWL&Linz / Hoersching-Flughafen*LOWS&Salzburg-Flughafen*LOWW&Wien / Schwechat-Flughafen%-Azerbaijan*UBBB&Baku / Bine Airport%-Bahamas*MYGF&Freeport, Grand Bahama*MYNN&Nassau Airport%-Bahrain*OBBI&Bahrain International Airport %-Bangladesh*VGEG&Chittagong Patenga *VGZR&Kurmitola, Dia%-Barbados*TBPB&Grantley Adams%-Belarus*UMMS&Minsk*EVRA&Riga Airport*UMII&Vitebsk%-Belgium*EBAW&Antwerpen / Deurne*EBBE&Beauvechain*EBLG&Bierset*EBBT&Brasschaat*EBBR&Bruxelles National*EBCI&Charleroi / Gosselies*EBCV&Chievres*EBLB&Elsenborn*EBFS&Florennes*EBTN&Goetsenhoven*EBBL&Kleine Brogel*EBFN&Koksijde*EBOS&Oostende Airport *EBDT&Schaffen*EBSP&Spa / La Sauveniere%-Belize*MZBZ&Belize / Phillip Goldston Intl. Airport%-Benin*DBBB&Cotonou%-Bermuda*TXKF&Bermuda%*/ $row = explode ('-', $string); foreach ($row as $therow){ $inrow = explode ('*', $therow); $i=1; foreach ($inrow as $newrow){ if ($i=="1"){ $country=$newrow; echo "<br>$country<br>"; }else{ $code_location = explode('%', $newrow); foreach($code_location as $last){ $codes = explode('&', $last); $code=$codes[0]; $location=$codes[1]; echo "$code -> $location<br>"; } } $i++; } } now the only problem i have is with the - loop because some location names contains some so it breaks the loop ... thats why i thought it would be good to use soem regex instead. Quote Link to comment Share on other sites More sharing options...
drisate Posted September 16, 2008 Author Share Posted September 16, 2008 I found a way $string=str_replace("\n", '*', str_replace("\r", '', $string)); $string=str_replace('* ', '*', $string); $string=str_replace(' * ', '*', $string); $string=str_replace('->', '&', $string); $string=str_replace(' & ', '&', $string); $row = explode ('*+*', $string); foreach ($row as $therow){ $inrow = explode ('*', $therow); $i=1; foreach ($inrow as $newrow){ if ($i=="1"){ $country=$newrow; echo "<br>$country<br>"; }else{ $code_location = explode('%', $newrow); foreach($code_location as $last){ $codes = explode('&', $last); $code=$codes[0]; $location=$codes[1]; echo "$code -> $location<br>"; } } $i++; } } But don't you have the feeling this is the worst way of doing this? ... i do ... Quote Link to comment Share on other sites More sharing options...
effigy Posted September 16, 2008 Share Posted September 16, 2008 <pre> <?php $data = <<<DATA -Albania LATI -> Tirana + -Angola FNLU -> Luanda + -Antarctic NZCM -> Williams Field + -Antigua and Barbuda TAPA -> Vc Bird International Airport Antigua + -Algeria DAUA -> Adrar DABB -> Annaba DABC -> Constantine DAAG -> Dar-El-Beida DAUG -> Ghardaia DAUH -> Hassi-Messaoud DAUZ -> In Amenas DAOO -> Oran / Es Senia DAAT -> Tamanrasset / Aguenna DABS -> Tebessa DAON -> Tlemcen Zenata + -Argentina SABE -> Aeroparque Bs. As. Aerodrome SAZB -> Bahia Blanca Aerodrome SAZS -> Bariloche Aerodrome SAVC -> Comodoro Rivadavia Aerodrome SAAC -> Concordia Aerodrome SACO -> Cordoba Aerodrome SARC -> Corrientes Aero. SADD -> Don Torcuato Aerodrome SAEZ -> Ezeiza Aerodrome SARF -> Formosa Aerodrome SARI -> Iguazu Aerodrome SASJ -> Jujuy Aerodrome SAZM -> Mar Del Plata Aerodrome SAME -> Mendoza Aerodrome SAZN -> Neuquen Aerodrome SARL -> Paso De Los Libres Aerodrome SARP -> Posadas Aero. SARE -> Resistencia Aero. SAWG -> Rio Gallegos Aerodrome SAWE -> Rio Grande B. A. SAAR -> Rosario Aerodrome SASA -> Salta Aerodrome SANU -> San Juan Aerodrome SANE -> Santiago Del Estero Aero. SAAV -> Sauce Viejo Aerodrome SAVT -> Trelew Aerodrome SANT -> Tucuman Aerodrome SAOR -> Villa Reynolds Aerodrome + -Armenia UGEE -> Yerevan + -Aruba TNCA -> Queen Beatrix Airport, Aruba + -Australia YPAD -> Adelaide Airport YBAS -> Alice Springs Aerodrome YPPH -> Belmont Perth Airport YBBN -> Brisbane Airport M. O YBRM -> Broome Airport YPEA -> Bullsbrook Pearce Amo YBCS -> Cairns Airport YSCB -> Canberra YPDN -> Darwin Airport YSDU -> Dubbo YMHB -> Hobart Airport YPTN -> Katherine Aerodrome YPLM -> Learmonth Airport YMML -> Melbourne Airport YSNF -> Norfolk Island Airport YPPD -> Port Hedland Pardoo YSRI -> Richmond Aus-Afb YBRK -> Rockhampton Airport YSSY -> Sydney Airport YBTL -> Townsville Amo + -Austria LOWG -> Graz-Thalerhof-Flughafen LOWI -> Innsbruck-Flughafen LOWK -> Klagenfurt-Flughafen LOWL -> Linz / Hoersching-Flughafen LOWS -> Salzburg-Flughafen LOWW -> Wien / Schwechat-Flughafen + -Azerbaijan UBBB -> Baku / Bine Airport + -Bahamas MYGF -> Freeport, Grand Bahama MYNN -> Nassau Airport + -Bahrain OBBI -> Bahrain International Airport + -Bangladesh VGEG -> Chittagong Patenga VGZR -> Kurmitola, Dia + -Barbados TBPB -> Grantley Adams + -Belarus UMMS -> Minsk EVRA -> Riga Airport UMII -> Vitebsk + -Belgium EBAW -> Antwerpen / Deurne EBBE -> Beauvechain EBLG -> Bierset EBBT -> Brasschaat EBBR -> Bruxelles National EBCI -> Charleroi / Gosselies EBCV -> Chievres EBLB -> Elsenborn EBFS -> Florennes EBTN -> Goetsenhoven EBBL -> Kleine Brogel EBFN -> Koksijde EBOS -> Oostende Airport EBDT -> Schaffen EBSP -> Spa / La Sauveniere + -Belize MZBZ -> Belize / Phillip Goldston Intl. Airport + -Benin DBBB -> Cotonou + -Bermuda TXKF -> Bermuda + -Bolivia SLCA -> Camiri SLCN -> Charana SLCO -> Cobija SLCB -> Cochabamba SLCP -> Concepcion SLLP -> La Paz / Alto SLMG -> Magdalena SLOR -> Oruro SLPO -> Potosi SLPS -> Puerto Suarez SLRY -> Reyes SLRI -> Riberalta SLRB -> Robore SLRQ -> Rurrenabaque SLSI -> San Ignacio De Velasco SLJO -> San Joaquin SLJE -> San Jose De Chiquitos SLSA -> Santa Ana SLSU -> Sucre SLTJ -> Tarija SLTR -> Trinidad SLVM -> Villamontes SLVR -> Viru-Viru SLYA -> Yacuiba + -Botswana FBFT -> Francistown FBGZ -> Ghanzi FBJW -> Jwaneng FBKE -> Kasane FBMN -> Maun FBSK -> Seretse Khama International Airport FBSW -> Shakawe FBTS -> Tsabong FBTE -> Tshane + -Brazil SBAF -> Afonsos Aeroporto SBAT -> Alta Floresta Aeroporto SBHT -> Altamira SBAR -> Aracaju Aeroporto SBBG -> Bage Aeroporto SBBU -> Bauru SBBE -> Belem Aeroporto SBCF -> Belo Horizonte SBBH -> Belo Horizonte Aeroporto SBBV -> Boa Vista Aeropor-To SBBR -> Brasilia Aeroporto SBKG -> Campina Grande SBKP -> Campinas Aeroporto SBCG -> Campo Grande Aeroporto SBCV -> Caravelas Aeropor-To SBAA -> Conceicao Do Araguaia SBCR -> Corumba SBCY -> Cuiaba Aeroporto SBBI -> Curitiba SBCT -> Curitiba Aeroporto SBEG -> Eduardo Gomes International SBFN -> Fernando De Noronha SBFL -> Florianopolis Aeroporto SBFZ -> Fortaleza Aeropor-To SBFI -> Foz Do Iguacu Aeroporto SBGL -> Galeao SBGO -> Goiania Aeroporto SBGW -> Guaratingueta SBGR -> Guarulhos Civ / Mil SBIL -> Ilheus Aeroporto SBIZ -> Imperatriz SBIH -> Itaituba SBLO -> Londrina Aeroporto SBME -> Macae SBMQ -> Macapa SBMO -> Maceio Aeroporto SBMN -> Manaus Aeroporto SBMA -> Maraba SBMT -> Marte Civ / Mil SBNT -> Natal Aeroporto SBPK -> Pelotas SBYS -> Pirassununga SBPC -> Pocos De Caldas SBPP -> Ponta Pora Aeropor-To SBCO -> Porto Alegre SBPA -> Porto Alegre Aero-Porto SBPN -> Porto Nacional Aeroporto SBPV -> Porto Velho Aeroporto SBDN -> Presidente Prudente SBRF -> Recife Aeroporto SBJR -> Rio / Jacarepagua SBRB -> Rio Branco SBRJ -> Rio De Janeiro Aeroporto SBSV -> Salvador Aeroporto SBSC -> Santa Cruz Aeropor-To SBSM -> Santa Maria Aero-Porto SBSN -> Santarem-Aeroporto SBST -> Santos Aeroporto SBSJ -> Sao Jose Dos Campo SBSL -> Sao Luiz Aeroporto SBSP -> Sao Paulo Aeropor-To SBTT -> Tabatinga SBTF -> Tefe SBTE -> Teresina Aeroporto SBTU -> Tucurui SBUR -> Uberaba SBUG -> Uruguaiana Aeroporto SBVH -> Vilhena Aeroporto SBVT -> Vitoria Aeroporto + -British Indian Ocean Territory FJDG -> Diego Garcia + -Brunei Darussalam WBSB -> Brunei Airport + -Bulgaria LBBG -> Burgas LBPD -> Plovdiv LBSF -> Sofia Observ. LBWN -> Varna + -Burundi HBBA -> Bujumbura + -Cambodia VDPP -> Phnom-Penh / Pochentong + -Cameroon FKKD -> Douala Obs. + -Canada CYXX -> Abbotsford, B. C. CYBG -> Bagotville, Que. CYYC -> Calgary International, Alta. CYCB -> Cambridge Bay, N. W. T. CYCH -> Chatham Can-Mil CZUM -> Churchill Falls, Nfld. CYYQ -> Churchill, Man. CYOD -> Cold Lake, Alta. CYQQ -> Comox, B. C. CYZS -> Coral Harbour, N. W. T. CYEG -> Edmonton International, Alta. CYET -> Edson, Alta. CZFM -> Fort Mcpherson Airport CYFC -> Fredericton, N. B. CYQX -> Gander Int. Airport, Nfld. CYYR -> Goose, Nfld. CYZX -> Greenwood, N. S. CYHZ -> Halifax International Airport CYFB -> Iqaluit, N. W. T. CYAH -> La Grande Iv, Que. CYGL -> La Grande Riviere, Que CYZY -> Mackenzie, B. C. CYNM -> Matagami, Que. CYXH -> Medicine Hat, Alta. CYQM -> Moncton, N. B. CYUL -> Montreal / Dorval International, Que CYMX -> Montreal / Mirabel CYBU -> Nipawin, Sask. CYOC -> Old Crow Airport CYOW -> Ottawa Int'L. Ont. CYYF -> Penticton, B. C. CYZT -> Port Hardy, B. C. CYPG -> Portage Southport A CYQB -> Quebec, Que CYUY -> Rouyn Airport CWZZ -> Saglek Bay CYAY -> Saint Anthony Airport CYZV -> Sept-Iles, Que. CYAW -> Shearwater, N. S. CYUA -> Shingle Point, Y. T. CYYT -> St. John's, Nfld CYJT -> Stephenville, Nfld. CYYN -> Swift Current, Sask. CYQY -> Sydney, N. S. CYTH -> Thompson Weather Office, Man CYYZ -> Toronto Pearson Int'L. Ont. CYTR -> Trenton, Ont. CYVR -> Vancouver International Air-Port, B. C. CYYJ -> Victoria Int. Airportb. C. CYQG -> Windsor, Ont. CYWG -> Winnipeg Int. Airportman. CYZF -> Yellowknife, N. W. T. + -Cape Verde GVAC -> Sal + -Cayman Islands MWCR -> Owen Roberts Airportgrand Cayman + -Central African Republic FEFF -> Bangui + -Chad FTTJ -> Ndjamena + -Chile SCFA -> Antofagasta SCAR -> Arica SCIE -> Concepcion SCHA -> Copiapo SCDA -> Iquique / Diego Arac SCIP -> Isla De Pascua SCSE -> La Serena SCEL -> Pudahuel SCTE -> Puerto Montt SCCI -> Punta Arenas + -China ZBAA -> Beijing ZUUU -> Chengdu ZYTL -> Dalian ZGGG -> Guangzhou ZSHC -> Hangzhou ZSOF -> Hefei ZPPP -> Kunming ZGNN -> Nanning ZSSS -> Shanghai / Hongqiao ZGSZ -> Shenzhen ZBYN -> Taiyuan ZBTJ -> Tianjin / Zhangguizhu ZWWW -> Urum-Qi / Diwopu ZSAM -> Xiamen + -Christmas Island YPXM -> Christmas Island Aerodrome YPCC -> Cocos Island Airport + -Colombia SKBQ -> Barranquilla / Ernestocortissoz SKBO -> Bogota / Eldorado SKBG -> Bucaramanga / Palonegro SKCL -> Cali / Alfonso Bonillaaragon SKCG -> Cartagena / Rafael Nunez SKLT -> Leticia / Vasquez Cobo SKMD -> Medellin / Olaya Herrera SKPE -> Pereira / Matecana SKRG -> Rionegro / J. M. Cordova SKSP -> San Andres Isla / Sesquicentenario SKSM -> Santa Marta / Simon Bolivar + -Comoros FMCZ -> Dzaoudzi / Pamanzi Mayotte FMCH -> Hahaya International Airport + -Congo FCBB -> Brazzaville / Maya-Maya FCPP -> Pointe-Noire + -Cook Islands NCRG -> Rarotonga + -Costa Rica MRCH -> Chacarita MROC -> Juan Santamaria MRLB -> Liberia MRLM -> Puerto Limon MRPV -> Tobias Bolanos International + -Cote D'Ivoire DIAP -> Abidjan + -Croatia LDDU -> Dubrovnik / Cilipi LDPL -> Pula Aerodrome LDRI -> Rijeka / Omisalj LDSP -> Split / Resnik LDZD -> Zadar / Zemunik LDZA -> Zagreb / Pleso + DATA; $result = array(); $countries = preg_split('/\s*\+\s*/', $data, -1, PREG_SPLIT_NO_EMPTY); foreach ($countries as $country) { ### Retrieve name. preg_match('/^\s*-(.+)/', $country, $country_name); $country_name = trim($country_name[1]); ### Retrieve code pairs. preg_match_all('/^\s*([A-Z]+) -> (.+)/m', $country, $code_pairs); $i = 0; foreach ($code_pairs[1] as $abbrev) { $result[$country_name][$abbrev] = $code_pairs[2][$i]; ++$i; } } print_r($result); ?> </pre> Quote Link to comment Share on other sites More sharing options...
drisate Posted September 16, 2008 Author Share Posted September 16, 2008 OMG! ... thats a lot better ! I really need to get a hang on regex ... Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted September 16, 2008 Share Posted September 16, 2008 But don't you have the feeling this is the worst way of doing this? ... i do ... Don't feel bad.. at least you put effort into it. Many people just want all the work done for them. I too often find myself doing things that could be much more streamlined and efficient. But that's the beauty of having knowledgeable people on forums like this, we learn by more experienced examples. As for learning regex, yep.. definitely a very handy tool to get a good grasp on. Many people (previously myself included) find it hard / intimidating. But once you start to really get on the ball, you learn to rapidly appreciate the regex engine's raw capabilities... makes life a lot easier to be sure. The syntax is not so hard..just learning the subtle 'rules of engagement'. If you haven't heard of this book before, you will now. I highly suggest picking up 'Mastering Regular Expressions' by Jeffrey Friedl (ISBN: 0-596-52812-4). Fantastic book that truly blows regex wide open and really helps illustrate what happens under the hood. Cheers, NRG Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.