From 253178cdb1fb440f4bc060f38e51253b4781bcf1 Mon Sep 17 00:00:00 2001 From: Martin Lindhe Date: Fri, 16 Oct 2015 21:26:03 +0200 Subject: [PATCH] make functional --- composer.json | 2 +- data/calling_codes.csv | 278 ++++++++ data/calling_codes.json | 1110 ++++++++++++++++++++++++++++++++ php/CallingCode.php | 6 +- php/README.md | 6 +- tools/update_calling_codes.php | 108 ++-- 6 files changed, 1430 insertions(+), 80 deletions(-) create mode 100644 data/calling_codes.csv create mode 100644 data/calling_codes.json diff --git a/composer.json b/composer.json index b8fea62..c6e9677 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "martinlindhe/data-calling-codes", - "description": "Data set with calling codes based on ISO xxx", + "description": "Data set with calling codes based on https://en.wikipedia.org/wiki/List_of_country_calling_codes", "license": "MIT", "require": { "php": ">=5.4.0", diff --git a/data/calling_codes.csv b/data/calling_codes.csv new file mode 100644 index 0000000..d686c06 --- /dev/null +++ b/data/calling_codes.csv @@ -0,0 +1,278 @@ +code,country +7840,Abkhazia +7940,Abkhazia +99544,Abkhazia +93,Afghanistan +35818,"Åland Islands" +355,Albania +213,Algeria +1684,"American Samoa" +NorthAmericanNumberingPlan,"American Samoa" +376,Andorra +244,Angola +1264,Anguilla +1268,"Antigua and Barbuda" +54,Argentina +374,Armenia +297,Aruba +247,Ascension +61,Australia +672,"Australian External Territories" +43,Austria +994,Azerbaijan +1242,Bahamas +973,Bahrain +880,Bangladesh +1246,Barbados +1268,Barbuda +375,Belarus +32,Belgium +501,Belize +229,Benin +1441,Bermuda +975,Bhutan +591,Bolivia +387,"Bosnia and Herzegovina" +267,Botswana +55,Brazil +246,"British Indian Ocean Territory" +1284,"British Virgin Islands" +673,"Brunei Darussalam" +359,Bulgaria +226,"Burkina Faso" +257,Burundi +855,Cambodia +237,Cameroon +1,Canada +238,"Cape Verde" +1345,"Cayman Islands" +236,"Central African Republic" +235,Chad +64,"Chatham Island, New Zealand" +56,Chile +86,China +61,"Christmas Island" +61,"Cocos (Keeling) Islands" +57,Colombia +269,Comoros +242,Congo +243,"Congo, Democratic Republic of the (Zaire)" +682,"Cook Islands" +506,"Costa Rica" +225,"Côte d'Ivoire" +385,Croatia +53,Cuba +5399,"Guantanamo Bay, Cuba" +357,Cyprus +420,"Czech Republic" +45,Denmark +246,"Diego Garcia" +253,Djibouti +1767,Dominica +1809,"Dominican Republic" +1829,"Dominican Republic" +1849,"Dominican Republic" +670,"East Timor" +56,"Easter Island" +593,Ecuador +20,Egypt +503,"El Salvador" +"8812,8813","Ellipso (Mobile Satellite service)" +88213,"EMSAT (Mobile Satellite service)" +240,"Equatorial Guinea" +291,Eritrea +372,Estonia +251,Ethiopia +500,"Falkland Islands" +298,"Faroe Islands" +679,Fiji +358,Finland +33,France +596,"French Antilles" +594,"French Guiana" +689,"French Polynesia" +241,Gabon +220,Gambia +995,Georgia +49,Germany +233,Ghana +350,Gibraltar +881,"Global Mobile Satellite System (GMSS)" +"8818,8819","Globalstar (Mobile Satellite Service)" +30,Greece +299,Greenland +1473,Grenada +590,Guadeloupe +1671,Guam +502,Guatemala +44,Guernsey +224,Guinea +245,Guinea-Bissau +592,Guyana +509,Haiti +504,Honduras +852,"Hong Kong" +36,Hungary +354,Iceland +"8810,8811","ICO Global (Mobile Satellite Service)" +91,India +62,Indonesia +870,"Inmarsat SNAC" +800,"International Freephone Service" +808,"International Shared Cost Service (ISCS)" +98,Iran +964,Iraq +353,Ireland +"8816,8817","Iridium (Mobile Satellite service)" +44,"Isle of Man" +972,Israel +39,Italy +1876,Jamaica +4779,"Jan Mayen" +81,Japan +44,Jersey +962,Jordan +76,Kazakhstan +77,Kazakhstan +254,Kenya +686,Kiribati +850,"Korea, North" +82,"Korea, South" +965,Kuwait +996,Kyrgyzstan +856,Laos +371,Latvia +961,Lebanon +266,Lesotho +231,Liberia +218,Libya +423,Liechtenstein +370,Lithuania +352,Luxembourg +853,Macau +389,Macedonia +261,Madagascar +265,Malawi +60,Malaysia +960,Maldives +223,Mali +356,Malta +692,"Marshall Islands" +596,Martinique +222,Mauritania +230,Mauritius +262,Mayotte +52,Mexico +691,"Micronesia, Federated States of" +1808,"Midway Island, USA" +373,Moldova +377,Monaco +976,Mongolia +382,Montenegro +1664,Montserrat +212,Morocco +258,Mozambique +95,Myanmar +264,Namibia +674,Nauru +977,Nepal +31,Netherlands +1869,Nevis +687,"New Caledonia" +64,"New Zealand" +505,Nicaragua +227,Niger +234,Nigeria +683,Niue +672,"Norfolk Island" +90392,"Northern Cyprus" +1670,"Northern Mariana Islands" +47,Norway +968,Oman +92,Pakistan +680,Palau +970,"Palestine, State of" +507,Panama +675,"Papua New Guinea" +595,Paraguay +51,Peru +63,Philippines +64,"Pitcairn Islands" +48,Poland +351,Portugal +1787,"Puerto Rico" +1939,"Puerto Rico" +974,Qatar +262,Réunion +40,Romania +7,Russia +250,Rwanda +590,"Saint Barthélemy" +290,"Saint Helena" +1869,"Saint Kitts and Nevis" +1758,"Saint Lucia" +590,"Saint Martin (France)" +508,"Saint Pierre and Miquelon" +1784,"Saint Vincent and the Grenadines" +685,Samoa +378,"San Marino" +239,"São Tomé and Príncipe" +966,"Saudi Arabia" +221,Senegal +381,Serbia +248,Seychelles +232,"Sierra Leone" +65,Singapore +1721,"Sint Maarten (Netherlands)" +421,Slovakia +386,Slovenia +677,"Solomon Islands" +252,Somalia +27,"South Africa" +500,"South Georgia and the South Sandwich Islands" +99534,"South Ossetia" +211,"South Sudan" +34,Spain +94,"Sri Lanka" +249,Sudan +597,Suriname +4779,Svalbard +268,Swaziland +46,Sweden +41,Switzerland +963,Syria +886,Taiwan +992,Tajikistan +255,Tanzania +66,Thailand +88216,"Thuraya (Mobile Satellite service)" +228,Togo +690,Tokelau +676,Tonga +1868,"Trinidad and Tobago" +2908,"Tristan da Cunha" +216,Tunisia +90,Turkey +993,Turkmenistan +1649,"Turks and Caicos Islands" +688,Tuvalu +256,Uganda +380,Ukraine +971,"United Arab Emirates" +44,"United Kingdom" +1,"United States" +878,"Universal Personal Telecommunications (UPT)" +598,Uruguay +1340,"US Virgin Islands" +998,Uzbekistan +678,Vanuatu +58,Venezuela +3906698,"Vatican City State (Holy See)" +379,"Vatican City State (Holy See)" +84,Vietnam +1808,"Wake Island, USA" +681,"Wallis and Futuna" +967,Yemen +260,Zambia +255,Zanzibar +263,Zimbabwe diff --git a/data/calling_codes.json b/data/calling_codes.json new file mode 100644 index 0000000..bc11df3 --- /dev/null +++ b/data/calling_codes.json @@ -0,0 +1,1110 @@ +[ + { + "country": "Abkhazia", + "code": "7840" + }, + { + "country": "Abkhazia", + "code": "7940" + }, + { + "country": "Abkhazia", + "code": "99544" + }, + { + "country": "Afghanistan", + "code": "93" + }, + { + "country": "Åland Islands", + "code": "35818" + }, + { + "country": "Albania", + "code": "355" + }, + { + "country": "Algeria", + "code": "213" + }, + { + "country": "American Samoa", + "code": "1684" + }, + { + "country": "American Samoa", + "code": "NorthAmericanNumberingPlan" + }, + { + "country": "Andorra", + "code": "376" + }, + { + "country": "Angola", + "code": "244" + }, + { + "country": "Anguilla", + "code": "1264" + }, + { + "country": "Antigua and Barbuda", + "code": "1268" + }, + { + "country": "Argentina", + "code": "54" + }, + { + "country": "Armenia", + "code": "374" + }, + { + "country": "Aruba", + "code": "297" + }, + { + "country": "Ascension", + "code": "247" + }, + { + "country": "Australia", + "code": "61" + }, + { + "country": "Australian External Territories", + "code": "672" + }, + { + "country": "Austria", + "code": "43" + }, + { + "country": "Azerbaijan", + "code": "994" + }, + { + "country": "Bahamas", + "code": "1242" + }, + { + "country": "Bahrain", + "code": "973" + }, + { + "country": "Bangladesh", + "code": "880" + }, + { + "country": "Barbados", + "code": "1246" + }, + { + "country": "Barbuda", + "code": "1268" + }, + { + "country": "Belarus", + "code": "375" + }, + { + "country": "Belgium", + "code": "32" + }, + { + "country": "Belize", + "code": "501" + }, + { + "country": "Benin", + "code": "229" + }, + { + "country": "Bermuda", + "code": "1441" + }, + { + "country": "Bhutan", + "code": "975" + }, + { + "country": "Bolivia", + "code": "591" + }, + { + "country": "Bosnia and Herzegovina", + "code": "387" + }, + { + "country": "Botswana", + "code": "267" + }, + { + "country": "Brazil", + "code": "55" + }, + { + "country": "British Indian Ocean Territory", + "code": "246" + }, + { + "country": "British Virgin Islands", + "code": "1284" + }, + { + "country": "Brunei Darussalam", + "code": "673" + }, + { + "country": "Bulgaria", + "code": "359" + }, + { + "country": "Burkina Faso", + "code": "226" + }, + { + "country": "Burundi", + "code": "257" + }, + { + "country": "Cambodia", + "code": "855" + }, + { + "country": "Cameroon", + "code": "237" + }, + { + "country": "Canada", + "code": "1" + }, + { + "country": "Cape Verde", + "code": "238" + }, + { + "country": "Cayman Islands", + "code": "1345" + }, + { + "country": "Central African Republic", + "code": "236" + }, + { + "country": "Chad", + "code": "235" + }, + { + "country": "Chatham Island, New Zealand", + "code": "64" + }, + { + "country": "Chile", + "code": "56" + }, + { + "country": "China", + "code": "86" + }, + { + "country": "Christmas Island", + "code": "61" + }, + { + "country": "Cocos (Keeling) Islands", + "code": "61" + }, + { + "country": "Colombia", + "code": "57" + }, + { + "country": "Comoros", + "code": "269" + }, + { + "country": "Congo", + "code": "242" + }, + { + "country": "Congo, Democratic Republic of the (Zaire)", + "code": "243" + }, + { + "country": "Cook Islands", + "code": "682" + }, + { + "country": "Costa Rica", + "code": "506" + }, + { + "country": "Côte d'Ivoire", + "code": "225" + }, + { + "country": "Croatia", + "code": "385" + }, + { + "country": "Cuba", + "code": "53" + }, + { + "country": "Guantanamo Bay, Cuba", + "code": "5399" + }, + { + "country": "Cyprus", + "code": "357" + }, + { + "country": "Czech Republic", + "code": "420" + }, + { + "country": "Denmark", + "code": "45" + }, + { + "country": "Diego Garcia", + "code": "246" + }, + { + "country": "Djibouti", + "code": "253" + }, + { + "country": "Dominica", + "code": "1767" + }, + { + "country": "Dominican Republic", + "code": "1809" + }, + { + "country": "Dominican Republic", + "code": "1829" + }, + { + "country": "Dominican Republic", + "code": "1849" + }, + { + "country": "East Timor", + "code": "670" + }, + { + "country": "Easter Island", + "code": "56" + }, + { + "country": "Ecuador", + "code": "593" + }, + { + "country": "Egypt", + "code": "20" + }, + { + "country": "El Salvador", + "code": "503" + }, + { + "country": "Ellipso (Mobile Satellite service)", + "code": "8812,8813" + }, + { + "country": "EMSAT (Mobile Satellite service)", + "code": "88213" + }, + { + "country": "Equatorial Guinea", + "code": "240" + }, + { + "country": "Eritrea", + "code": "291" + }, + { + "country": "Estonia", + "code": "372" + }, + { + "country": "Ethiopia", + "code": "251" + }, + { + "country": "Falkland Islands", + "code": "500" + }, + { + "country": "Faroe Islands", + "code": "298" + }, + { + "country": "Fiji", + "code": "679" + }, + { + "country": "Finland", + "code": "358" + }, + { + "country": "France", + "code": "33" + }, + { + "country": "French Antilles", + "code": "596" + }, + { + "country": "French Guiana", + "code": "594" + }, + { + "country": "French Polynesia", + "code": "689" + }, + { + "country": "Gabon", + "code": "241" + }, + { + "country": "Gambia", + "code": "220" + }, + { + "country": "Georgia", + "code": "995" + }, + { + "country": "Germany", + "code": "49" + }, + { + "country": "Ghana", + "code": "233" + }, + { + "country": "Gibraltar", + "code": "350" + }, + { + "country": "Global Mobile Satellite System (GMSS)", + "code": "881" + }, + { + "country": "Globalstar (Mobile Satellite Service)", + "code": "8818,8819" + }, + { + "country": "Greece", + "code": "30" + }, + { + "country": "Greenland", + "code": "299" + }, + { + "country": "Grenada", + "code": "1473" + }, + { + "country": "Guadeloupe", + "code": "590" + }, + { + "country": "Guam", + "code": "1671" + }, + { + "country": "Guatemala", + "code": "502" + }, + { + "country": "Guernsey", + "code": "44" + }, + { + "country": "Guinea", + "code": "224" + }, + { + "country": "Guinea-Bissau", + "code": "245" + }, + { + "country": "Guyana", + "code": "592" + }, + { + "country": "Haiti", + "code": "509" + }, + { + "country": "Honduras", + "code": "504" + }, + { + "country": "Hong Kong", + "code": "852" + }, + { + "country": "Hungary", + "code": "36" + }, + { + "country": "Iceland", + "code": "354" + }, + { + "country": "ICO Global (Mobile Satellite Service)", + "code": "8810,8811" + }, + { + "country": "India", + "code": "91" + }, + { + "country": "Indonesia", + "code": "62" + }, + { + "country": "Inmarsat SNAC", + "code": "870" + }, + { + "country": "International Freephone Service", + "code": "800" + }, + { + "country": "International Shared Cost Service (ISCS)", + "code": "808" + }, + { + "country": "Iran", + "code": "98" + }, + { + "country": "Iraq", + "code": "964" + }, + { + "country": "Ireland", + "code": "353" + }, + { + "country": "Iridium (Mobile Satellite service)", + "code": "8816,8817" + }, + { + "country": "Isle of Man", + "code": "44" + }, + { + "country": "Israel", + "code": "972" + }, + { + "country": "Italy", + "code": "39" + }, + { + "country": "Jamaica", + "code": "1876" + }, + { + "country": "Jan Mayen", + "code": "4779" + }, + { + "country": "Japan", + "code": "81" + }, + { + "country": "Jersey", + "code": "44" + }, + { + "country": "Jordan", + "code": "962" + }, + { + "country": "Kazakhstan", + "code": "76" + }, + { + "country": "Kazakhstan", + "code": "77" + }, + { + "country": "Kenya", + "code": "254" + }, + { + "country": "Kiribati", + "code": "686" + }, + { + "country": "Korea, North", + "code": "850" + }, + { + "country": "Korea, South", + "code": "82" + }, + { + "country": "Kuwait", + "code": "965" + }, + { + "country": "Kyrgyzstan", + "code": "996" + }, + { + "country": "Laos", + "code": "856" + }, + { + "country": "Latvia", + "code": "371" + }, + { + "country": "Lebanon", + "code": "961" + }, + { + "country": "Lesotho", + "code": "266" + }, + { + "country": "Liberia", + "code": "231" + }, + { + "country": "Libya", + "code": "218" + }, + { + "country": "Liechtenstein", + "code": "423" + }, + { + "country": "Lithuania", + "code": "370" + }, + { + "country": "Luxembourg", + "code": "352" + }, + { + "country": "Macau", + "code": "853" + }, + { + "country": "Macedonia", + "code": "389" + }, + { + "country": "Madagascar", + "code": "261" + }, + { + "country": "Malawi", + "code": "265" + }, + { + "country": "Malaysia", + "code": "60" + }, + { + "country": "Maldives", + "code": "960" + }, + { + "country": "Mali", + "code": "223" + }, + { + "country": "Malta", + "code": "356" + }, + { + "country": "Marshall Islands", + "code": "692" + }, + { + "country": "Martinique", + "code": "596" + }, + { + "country": "Mauritania", + "code": "222" + }, + { + "country": "Mauritius", + "code": "230" + }, + { + "country": "Mayotte", + "code": "262" + }, + { + "country": "Mexico", + "code": "52" + }, + { + "country": "Micronesia, Federated States of", + "code": "691" + }, + { + "country": "Midway Island, USA", + "code": "1808" + }, + { + "country": "Moldova", + "code": "373" + }, + { + "country": "Monaco", + "code": "377" + }, + { + "country": "Mongolia", + "code": "976" + }, + { + "country": "Montenegro", + "code": "382" + }, + { + "country": "Montserrat", + "code": "1664" + }, + { + "country": "Morocco", + "code": "212" + }, + { + "country": "Mozambique", + "code": "258" + }, + { + "country": "Myanmar", + "code": "95" + }, + { + "country": "Namibia", + "code": "264" + }, + { + "country": "Nauru", + "code": "674" + }, + { + "country": "Nepal", + "code": "977" + }, + { + "country": "Netherlands", + "code": "31" + }, + { + "country": "Nevis", + "code": "1869" + }, + { + "country": "New Caledonia", + "code": "687" + }, + { + "country": "New Zealand", + "code": "64" + }, + { + "country": "Nicaragua", + "code": "505" + }, + { + "country": "Niger", + "code": "227" + }, + { + "country": "Nigeria", + "code": "234" + }, + { + "country": "Niue", + "code": "683" + }, + { + "country": "Norfolk Island", + "code": "672" + }, + { + "country": "Northern Cyprus", + "code": "90392" + }, + { + "country": "Northern Mariana Islands", + "code": "1670" + }, + { + "country": "Norway", + "code": "47" + }, + { + "country": "Oman", + "code": "968" + }, + { + "country": "Pakistan", + "code": "92" + }, + { + "country": "Palau", + "code": "680" + }, + { + "country": "Palestine, State of", + "code": "970" + }, + { + "country": "Panama", + "code": "507" + }, + { + "country": "Papua New Guinea", + "code": "675" + }, + { + "country": "Paraguay", + "code": "595" + }, + { + "country": "Peru", + "code": "51" + }, + { + "country": "Philippines", + "code": "63" + }, + { + "country": "Pitcairn Islands", + "code": "64" + }, + { + "country": "Poland", + "code": "48" + }, + { + "country": "Portugal", + "code": "351" + }, + { + "country": "Puerto Rico", + "code": "1787" + }, + { + "country": "Puerto Rico", + "code": "1939" + }, + { + "country": "Qatar", + "code": "974" + }, + { + "country": "Réunion", + "code": "262" + }, + { + "country": "Romania", + "code": "40" + }, + { + "country": "Russia", + "code": "7" + }, + { + "country": "Rwanda", + "code": "250" + }, + { + "country": "Saint Barthélemy", + "code": "590" + }, + { + "country": "Saint Helena", + "code": "290" + }, + { + "country": "Saint Kitts and Nevis", + "code": "1869" + }, + { + "country": "Saint Lucia", + "code": "1758" + }, + { + "country": "Saint Martin (France)", + "code": "590" + }, + { + "country": "Saint Pierre and Miquelon", + "code": "508" + }, + { + "country": "Saint Vincent and the Grenadines", + "code": "1784" + }, + { + "country": "Samoa", + "code": "685" + }, + { + "country": "San Marino", + "code": "378" + }, + { + "country": "São Tomé and Príncipe", + "code": "239" + }, + { + "country": "Saudi Arabia", + "code": "966" + }, + { + "country": "Senegal", + "code": "221" + }, + { + "country": "Serbia", + "code": "381" + }, + { + "country": "Seychelles", + "code": "248" + }, + { + "country": "Sierra Leone", + "code": "232" + }, + { + "country": "Singapore", + "code": "65" + }, + { + "country": "Sint Maarten (Netherlands)", + "code": "1721" + }, + { + "country": "Slovakia", + "code": "421" + }, + { + "country": "Slovenia", + "code": "386" + }, + { + "country": "Solomon Islands", + "code": "677" + }, + { + "country": "Somalia", + "code": "252" + }, + { + "country": "South Africa", + "code": "27" + }, + { + "country": "South Georgia and the South Sandwich Islands", + "code": "500" + }, + { + "country": "South Ossetia", + "code": "99534" + }, + { + "country": "South Sudan", + "code": "211" + }, + { + "country": "Spain", + "code": "34" + }, + { + "country": "Sri Lanka", + "code": "94" + }, + { + "country": "Sudan", + "code": "249" + }, + { + "country": "Suriname", + "code": "597" + }, + { + "country": "Svalbard", + "code": "4779" + }, + { + "country": "Swaziland", + "code": "268" + }, + { + "country": "Sweden", + "code": "46" + }, + { + "country": "Switzerland", + "code": "41" + }, + { + "country": "Syria", + "code": "963" + }, + { + "country": "Taiwan", + "code": "886" + }, + { + "country": "Tajikistan", + "code": "992" + }, + { + "country": "Tanzania", + "code": "255" + }, + { + "country": "Thailand", + "code": "66" + }, + { + "country": "Thuraya (Mobile Satellite service)", + "code": "88216" + }, + { + "country": "Togo", + "code": "228" + }, + { + "country": "Tokelau", + "code": "690" + }, + { + "country": "Tonga", + "code": "676" + }, + { + "country": "Trinidad and Tobago", + "code": "1868" + }, + { + "country": "Tristan da Cunha", + "code": "2908" + }, + { + "country": "Tunisia", + "code": "216" + }, + { + "country": "Turkey", + "code": "90" + }, + { + "country": "Turkmenistan", + "code": "993" + }, + { + "country": "Turks and Caicos Islands", + "code": "1649" + }, + { + "country": "Tuvalu", + "code": "688" + }, + { + "country": "Uganda", + "code": "256" + }, + { + "country": "Ukraine", + "code": "380" + }, + { + "country": "United Arab Emirates", + "code": "971" + }, + { + "country": "United Kingdom", + "code": "44" + }, + { + "country": "United States", + "code": "1" + }, + { + "country": "Universal Personal Telecommunications (UPT)", + "code": "878" + }, + { + "country": "Uruguay", + "code": "598" + }, + { + "country": "US Virgin Islands", + "code": "1340" + }, + { + "country": "Uzbekistan", + "code": "998" + }, + { + "country": "Vanuatu", + "code": "678" + }, + { + "country": "Venezuela", + "code": "58" + }, + { + "country": "Vatican City State (Holy See)", + "code": "3906698" + }, + { + "country": "Vatican City State (Holy See)", + "code": "379" + }, + { + "country": "Vietnam", + "code": "84" + }, + { + "country": "Wake Island, USA", + "code": "1808" + }, + { + "country": "Wallis and Futuna", + "code": "681" + }, + { + "country": "Yemen", + "code": "967" + }, + { + "country": "Zambia", + "code": "260" + }, + { + "country": "Zanzibar", + "code": "255" + }, + { + "country": "Zimbabwe", + "code": "263" + } +] \ No newline at end of file diff --git a/php/CallingCode.php b/php/CallingCode.php index ec52050..3e7fdd9 100644 --- a/php/CallingCode.php +++ b/php/CallingCode.php @@ -2,8 +2,6 @@ class CallingCode { - var $name; - var $alpha2; - var $alpha3; - var $number; + var $country; + var $code; } diff --git a/php/README.md b/php/README.md index d4012bf..3457fa0 100644 --- a/php/README.md +++ b/php/README.md @@ -3,10 +3,10 @@ Seed your table by doing something like: ```php -foreach (MartinLindhe\DataCountries\Reader::asObjectList() as $o) { +foreach (MartinLindhe\Data\CallingCodes::all() as $cc) { Country::create([ - 'alpha3' => $o->alpha3, - 'name' => $o->name + 'alpha3' => $cc->alpha3, + 'name' => $cc->name ]); } ``` diff --git a/tools/update_calling_codes.php b/tools/update_calling_codes.php index b2236ae..002de09 100644 --- a/tools/update_calling_codes.php +++ b/tools/update_calling_codes.php @@ -1,52 +1,20 @@ '); - if ($p2 !== false) { - $s = substr($s, 0, $p1).substr($s, $p2 + strlen('-->')); - return cleanText($s); - } - return ''; - } - - $p1 = strpos($s, ''); - if ($p1 !== false) { - $p2 = strpos($s, ''); - if ($p2 !== false) { - $s = substr($s, 0, $p1).substr($s, $p2 + strlen('')); - return cleanText($s); - } - return ''; - } - - return $s; -} - function getRightSideOfMediawikiTag($t) { - $pos = mb_strpos($t, '{{'); + $start = '[['; + $pos = mb_strpos($t, $start); if ($pos === false) { return $t; } + $t = mb_substr($t, $pos + strlen($start)); - $pos2 = mb_strpos($t, '}}', $pos); + $pos2 = mb_strpos($t, ']]', $pos); if ($pos2 === false) { return $t; } @@ -60,24 +28,21 @@ function getRightSideOfMediawikiTag($t) return $t; } -function isAlpha3InList($alpha3, $list) +function cleanText($s) { - foreach ($list as $o) { - if ($o->alpha3 == $alpha3) { - return true; - } - } - return false; + $s = str_replace('|', '', $s); + $s = trim($s); + return $s; } function write_csv($fileName, $list) { $csv = League\Csv\Writer::createFromFileObject(new SplTempFileObject()); - $csv->insertOne(['alpha2', 'alpha3', 'number', 'name']); + $csv->insertOne(['code', 'country']); foreach ($list as $o) { - $csv->insertOne([$o->alpha2, $o->alpha3, $o->number, $o->name]); + $csv->insertOne([$o->code, $o->country]); } file_put_contents($fileName, $csv->__toString()); @@ -97,8 +62,8 @@ function write_json($fileName, $list) $x = $res->data; -$start = "Link to [[ISO 3166-2]] subdivision codes"."\n"."|-"."\n"; +$start = "! [[Daylight saving time|DST]]"."\n"."|-"."\n"; $pos = strpos($x, $start); if ($pos === false) { @@ -118,45 +83,44 @@ function write_json($fileName, $list) $data = substr($x, $pos, $pos2 - $pos); +function extractLinks($s) +{ + preg_match_all('/\[\[[\w\d\s,+|]+\]\]/', $s, $matches); + + return $matches[0]; +} + $list = []; $rows = explode("\n", $data); for ($i = 0; $i < count($rows); $i++) { - $rows[$i] = cleanText($rows[$i]); - if (!$rows[$i]) { + if (!$rows[$i] || $rows[$i] == '|-' || $rows[$i] == '|') { continue; } - $cols = explode('||', $rows[$i]); - if (count($cols) == 1) { - $name = $rows[$i]; - $i++; - $rows[$i] = cleanText($rows[$i]); - $cols = explode('||', $rows[$i]); - } + $country = cleanText($rows[$i++]); - $o = new \MartinLindhe\Data\CallingCodes\CallingCode; - $o->alpha2 = getRightSideOfMediawikiTag($cols[0]); - $o->alpha3 = getRightSideOfMediawikiTag($cols[1]); - $o->number = getRightSideOfMediawikiTag($cols[2]); - $name = cleanText($name); - $name = getRightSideOfMediawikiTag(\MartinLindhe\MediawikiClient\Client::stripMediawikiLinks($name)); + $codes = extractLinks($rows[$i++]); - $pos = mb_strpos($name, '/'); - if ($pos !== false) { - $name = mb_substr($name, 0, $pos); - } + $timezone = $rows[$i++]; + + + foreach ($codes as $c) { + + $code = getRightSideOfMediawikiTag($c); + $code = str_replace(' ', '', $code); + $code = str_replace('+', '', $code); + + $o = new \MartinLindhe\Data\CallingCodes\CallingCode; + $o->country = $country; + $o->code = $code; - $pos = mb_strpos($name, '|'); - if ($pos !== false) { - $name = mb_substr($name, $pos + 1); + $list[] = $o; } - $o->name = trim($name); - $list[] = $o; }