Skip to content

Instantly share code, notes, and snippets.

@pickletoni
Forked from AdonaiAraya/countryPhoneCodes.json
Last active November 14, 2024 20:26
Show Gist options
  • Save pickletoni/021e2e18e83f33d16fee5daa308e6a4e to your computer and use it in GitHub Desktop.
Save pickletoni/021e2e18e83f33d16fee5daa308e6a4e to your computer and use it in GitHub Desktop.
JSON array of 248 countries with phone codes and ISO country code
[{"country":"Afghanistan","code":"93","iso":"AF"},
{"country":"Albania","code":"355","iso":"AL"},
{"country":"Algeria","code":"213","iso":"DZ"},
{"country":"American Samoa","code":"1-684","iso":"AS"},
{"country":"Andorra","code":"376","iso":"AD"},
{"country":"Angola","code":"244","iso":"AO"},
{"country":"Anguilla","code":"1-264","iso":"AI"},
{"country":"Antarctica","code":"672","iso":"AQ"},
{"country":"Antigua and Barbuda","code":"1-268","iso":"AG"},
{"country":"Argentina","code":"54","iso":"AR"},
{"country":"Armenia","code":"374","iso":"AM"},
{"country":"Aruba","code":"297","iso":"AW"},
{"country":"Australia","code":"61","iso":"AU"},
{"country":"Austria","code":"43","iso":"AT"},
{"country":"Azerbaijan","code":"994","iso":"AZ"},
{"country":"Bahamas","code":"1-242","iso":"BS"},
{"country":"Bahrain","code":"973","iso":"BH"},
{"country":"Bangladesh","code":"880","iso":"BD"},
{"country":"Barbados","code":"1-246","iso":"BB"},
{"country":"Belarus","code":"375","iso":"BY"},
{"country":"Belgium","code":"32","iso":"BE"},
{"country":"Belize","code":"501","iso":"BZ"},
{"country":"Benin","code":"229","iso":"BJ"},
{"country":"Bermuda","code":"1-441","iso":"BM"},
{"country":"Bhutan","code":"975","iso":"BT"},
{"country":"Bolivia","code":"591","iso":"BO"},
{"country":"Bosnia and Herzegovina","code":"387","iso":"BA"},
{"country":"Botswana","code":"267","iso":"BW"},
{"country":"Brazil","code":"55","iso":"BR"},
{"country":"British Indian Ocean Territory","code":"246","iso":"IO"},
{"country":"British Virgin Islands","code":"1-284","iso":"VG"},
{"country":"Brunei","code":"673","iso":"BN"},
{"country":"Bulgaria","code":"359","iso":"BG"},
{"country":"Burkina Faso","code":"226","iso":"BF"},
{"country":"Burundi","code":"257","iso":"BI"},
{"country":"Cambodia","code":"855","iso":"KH"},
{"country":"Cameroon","code":"237","iso":"CM"},
{"country":"Canada","code":"1","iso":"CA"},
{"country":"Cape Verde","code":"238","iso":"CV"},
{"country":"Cayman Islands","code":"1-345","iso":"KY"},
{"country":"Central African Republic","code":"236","iso":"CF"},
{"country":"Chad","code":"235","iso":"TD"},
{"country":"Chile","code":"56","iso":"CL"},
{"country":"China","code":"86","iso":"CN"},
{"country":"Christmas Island","code":"61","iso":"CX"},
{"country":"Cocos Islands","code":"61","iso":"CC"},
{"country":"Colombia","code":"57","iso":"CO"},
{"country":"Comoros","code":"269","iso":"KM"},
{"country":"Cook Islands","code":"682","iso":"CK"},
{"country":"Costa Rica","code":"506","iso":"CR"},
{"country":"Croatia","code":"385","iso":"HR"},
{"country":"Cuba","code":"53","iso":"CU"},
{"country":"Curacao","code":"599","iso":"CW"},
{"country":"Cyprus","code":"357","iso":"CY"},
{"country":"Czech Republic","code":"420","iso":"CZ"},
{"country":"Democratic Republic of the Congo","code":"243","iso":"CD"},
{"country":"Denmark","code":"45","iso":"DK"},
{"country":"Djibouti","code":"253","iso":"DJ"},
{"country":"Dominica","code":"1-767","iso":"DM"},
{"country":"Dominican Republic","code":"1-809, 1-829, 1-849","iso":"DO"},
{"country":"East Timor","code":"670","iso":"TL"},
{"country":"Ecuador","code":"593","iso":"EC"},
{"country":"Egypt","code":"20","iso":"EG"},
{"country":"El Salvador","code":"503","iso":"SV"},
{"country":"Equatorial Guinea","code":"240","iso":"GQ"},
{"country":"Eritrea","code":"291","iso":"ER"},
{"country":"Estonia","code":"372","iso":"EE"},
{"country":"Ethiopia","code":"251","iso":"ET"},
{"country":"Falkland Islands","code":"500","iso":"FK"},
{"country":"Faroe Islands","code":"298","iso":"FO"},
{"country":"Fiji","code":"679","iso":"FJ"},
{"country":"Finland","code":"358","iso":"FI"},
{"country":"France","code":"33","iso":"FR"},
{"country":"French Polynesia","code":"689","iso":"PF"},
{"country":"Gabon","code":"241","iso":"GA"},
{"country":"Gambia","code":"220","iso":"GM"},
{"country":"Georgia","code":"995","iso":"GE"},
{"country":"Germany","code":"49","iso":"DE"},
{"country":"Ghana","code":"233","iso":"GH"},
{"country":"Gibraltar","code":"350","iso":"GI"},
{"country":"Greece","code":"30","iso":"GR"},
{"country":"Greenland","code":"299","iso":"GL"},
{"country":"Grenada","code":"1-473","iso":"GD"},
{"country":"Guam","code":"1-671","iso":"GU"},
{"country":"Guatemala","code":"502","iso":"GT"},
{"country":"Guernsey","code":"44-1481","iso":"GG"},
{"country":"Guinea","code":"224","iso":"GN"},
{"country":"Guinea-Bissau","code":"245","iso":"GW"},
{"country":"Guyana","code":"592","iso":"GY"},
{"country":"Haiti","code":"509","iso":"HT"},
{"country":"Honduras","code":"504","iso":"HN"},
{"country":"Hong Kong","code":"852","iso":"HK"},
{"country":"Hungary","code":"36","iso":"HU"},
{"country":"Iceland","code":"354","iso":"IS"},
{"country":"India","code":"91","iso":"IN"},
{"country":"Indonesia","code":"62","iso":"ID"},
{"country":"Iran","code":"98","iso":"IR"},
{"country":"Iraq","code":"964","iso":"IQ"},
{"country":"Ireland","code":"353","iso":"IE"},
{"country":"Isle of Man","code":"44-1624","iso":"IM"},
{"country":"Israel","code":"972","iso":"IL"},
{"country":"Italy","code":"39","iso":"IT"},
{"country":"Ivory Coast","code":"225","iso":"CI"},
{"country":"Jamaica","code":"1-876","iso":"JM"},
{"country":"Japan","code":"81","iso":"JP"},
{"country":"Jersey","code":"44-1534","iso":"JE"},
{"country":"Jordan","code":"962","iso":"JO"},
{"country":"Kazakhstan","code":"7","iso":"KZ"},
{"country":"Kenya","code":"254","iso":"KE"},
{"country":"Kiribati","code":"686","iso":"KI"},
{"country":"Kosovo","code":"383","iso":"XK"},
{"country":"Kuwait","code":"965","iso":"KW"},
{"country":"Kyrgyzstan","code":"996","iso":"KG"},
{"country":"Laos","code":"856","iso":"LA"},
{"country":"Latvia","code":"371","iso":"LV"},
{"country":"Lebanon","code":"961","iso":"LB"},
{"country":"Lesotho","code":"266","iso":"LS"},
{"country":"Liberia","code":"231","iso":"LR"},
{"country":"Libya","code":"218","iso":"LY"},
{"country":"Liechtenstein","code":"423","iso":"LI"},
{"country":"Lithuania","code":"370","iso":"LT"},
{"country":"Luxembourg","code":"352","iso":"LU"},
{"country":"Macao","code":"853","iso":"MO"},
{"country":"Macedonia","code":"389","iso":"MK"},
{"country":"Madagascar","code":"261","iso":"MG"},
{"country":"Malawi","code":"265","iso":"MW"},
{"country":"Malaysia","code":"60","iso":"MY"},
{"country":"Maldives","code":"960","iso":"MV"},
{"country":"Mali","code":"223","iso":"ML"},
{"country":"Malta","code":"356","iso":"MT"},
{"country":"Marshall Islands","code":"692","iso":"MH"},
{"country":"Mauritania","code":"222","iso":"MR"},
{"country":"Mauritius","code":"230","iso":"MU"},
{"country":"Mayotte","code":"262","iso":"YT"},
{"country":"Mexico","code":"52","iso":"MX"},
{"country":"Micronesia","code":"691","iso":"FM"},
{"country":"Moldova","code":"373","iso":"MD"},
{"country":"Monaco","code":"377","iso":"MC"},
{"country":"Mongolia","code":"976","iso":"MN"},
{"country":"Montenegro","code":"382","iso":"ME"},
{"country":"Montserrat","code":"1-664","iso":"MS"},
{"country":"Morocco","code":"212","iso":"MA"},
{"country":"Mozambique","code":"258","iso":"MZ"},
{"country":"Myanmar","code":"95","iso":"MM"},
{"country":"Namibia","code":"264","iso":"NA"},
{"country":"Nauru","code":"674","iso":"NR"},
{"country":"Nepal","code":"977","iso":"NP"},
{"country":"Netherlands","code":"31","iso":"NL"},
{"country":"Netherlands Antilles","code":"599","iso":"AN"},
{"country":"New Caledonia","code":"687","iso":"NC"},
{"country":"New Zealand","code":"64","iso":"NZ"},
{"country":"Nicaragua","code":"505","iso":"NI"},
{"country":"Niger","code":"227","iso":"NE"},
{"country":"Nigeria","code":"234","iso":"NG"},
{"country":"Niue","code":"683","iso":"NU"},
{"country":"North Korea","code":"850","iso":"KP"},
{"country":"Northern Mariana Islands","code":"1-670","iso":"MP"},
{"country":"Norway","code":"47","iso":"NO"},
{"country":"Oman","code":"968","iso":"OM"},
{"country":"Pakistan","code":"92","iso":"PK"},
{"country":"Palau","code":"680","iso":"PW"},
{"country":"Palestine","code":"970","iso":"PS"},
{"country":"Panama","code":"507","iso":"PA"},
{"country":"Papua New Guinea","code":"675","iso":"PG"},
{"country":"Paraguay","code":"595","iso":"PY"},
{"country":"Peru","code":"51","iso":"PE"},
{"country":"Philippines","code":"63","iso":"PH"},
{"country":"Pitcairn","code":"64","iso":"PN"},
{"country":"Poland","code":"48","iso":"PL"},
{"country":"Portugal","code":"351","iso":"PT"},
{"country":"Puerto Rico","code":"1-787, 1-939","iso":"PR"},
{"country":"Qatar","code":"974","iso":"QA"},
{"country":"Republic of the Congo","code":"242","iso":"CG"},
{"country":"Reunion","code":"262","iso":"RE"},
{"country":"Romania","code":"40","iso":"RO"},
{"country":"Russia","code":"7","iso":"RU"},
{"country":"Rwanda","code":"250","iso":"RW"},
{"country":"Saint Barthelemy","code":"590","iso":"BL"},
{"country":"Saint Helena","code":"290","iso":"SH"},
{"country":"Saint Kitts and Nevis","code":"1-869","iso":"KN"},
{"country":"Saint Lucia","code":"1-758","iso":"LC"},
{"country":"Saint Martin","code":"590","iso":"MF"},
{"country":"Saint Pierre and Miquelon","code":"508","iso":"PM"},
{"country":"Saint Vincent and the Grenadines","code":"1-784","iso":"VC"},
{"country":"Samoa","code":"685","iso":"WS"},
{"country":"San Marino","code":"378","iso":"SM"},
{"country":"Sao Tome and Principe","code":"239","iso":"ST"},
{"country":"Saudi Arabia","code":"966","iso":"SA"},
{"country":"Senegal","code":"221","iso":"SN"},
{"country":"Serbia","code":"381","iso":"RS"},
{"country":"Seychelles","code":"248","iso":"SC"},
{"country":"Sierra Leone","code":"232","iso":"SL"},
{"country":"Singapore","code":"65","iso":"SG"},
{"country":"Sint Maarten","code":"1-721","iso":"SX"},
{"country":"Slovakia","code":"421","iso":"SK"},
{"country":"Slovenia","code":"386","iso":"SI"},
{"country":"Solomon Islands","code":"677","iso":"SB"},
{"country":"Somalia","code":"252","iso":"SO"},
{"country":"South Africa","code":"27","iso":"ZA"},
{"country":"South Korea","code":"82","iso":"KR"},
{"country":"South Sudan","code":"211","iso":"SS"},
{"country":"Spain","code":"34","iso":"ES"},
{"country":"Sri Lanka","code":"94","iso":"LK"},
{"country":"Sudan","code":"249","iso":"SD"},
{"country":"Suriname","code":"597","iso":"SR"},
{"country":"Svalbard and Jan Mayen","code":"47","iso":"SJ"},
{"country":"Swaziland","code":"268","iso":"SZ"},
{"country":"Sweden","code":"46","iso":"SE"},
{"country":"Switzerland","code":"41","iso":"CH"},
{"country":"Syria","code":"963","iso":"SY"},
{"country":"Taiwan","code":"886","iso":"TW"},
{"country":"Tajikistan","code":"992","iso":"TJ"},
{"country":"Tanzania","code":"255","iso":"TZ"},
{"country":"Thailand","code":"66","iso":"TH"},
{"country":"Togo","code":"228","iso":"TG"},
{"country":"Tokelau","code":"690","iso":"TK"},
{"country":"Tonga","code":"676","iso":"TO"},
{"country":"Trinidad and Tobago","code":"1-868","iso":"TT"},
{"country":"Tunisia","code":"216","iso":"TN"},
{"country":"Turkey","code":"90","iso":"TR"},
{"country":"Turkmenistan","code":"993","iso":"TM"},
{"country":"Turks and Caicos Islands","code":"1-649","iso":"TC"},
{"country":"Tuvalu","code":"688","iso":"TV"},
{"country":"U.S. Virgin Islands","code":"1-340","iso":"VI"},
{"country":"Uganda","code":"256","iso":"UG"},
{"country":"Ukraine","code":"380","iso":"UA"},
{"country":"United Arab Emirates","code":"971","iso":"AE"},
{"country":"United Kingdom","code":"44","iso":"GB"},
{"country":"United States","code":"1","iso":"US"},
{"country":"Uruguay","code":"598","iso":"UY"},
{"country":"Uzbekistan","code":"998","iso":"UZ"},
{"country":"Vanuatu","code":"678","iso":"VU"},
{"country":"Vatican","code":"379","iso":"VA"},
{"country":"Venezuela","code":"58","iso":"VE"},
{"country":"Vietnam","code":"84","iso":"VN"},
{"country":"Wallis and Futuna","code":"681","iso":"WF"},
{"country":"Western Sahara","code":"212","iso":"EH"},
{"country":"Yemen","code":"967","iso":"YE"},
{"country":"Zambia","code":"260","iso":"ZM"},
{"country":"Zimbabwe","code":"263","iso":"ZW"}]
@swapnilshewale1
Copy link

thanks

@v0ff4k
Copy link

v0ff4k commented Nov 17, 2022

nope, non functional codes, for example:
how you make sense kz vs ru ? there both +7 !
Kazahstan +7 7****
where
Russia +7 8*** +7 9***

also +4*** has different codes + subcodes
refer to
https://en.wikipedia.org/wiki/List_of_country_calling_codes

@youssedmessaoudi
Copy link

$code_country =['213','376','244','1264','1268','54','374','297','61','43','994','1242','973','880','1246','375','32','501','229','1441','975','591','387','267','55','673','359','226','257','855','237','1','238','1345','236','56','86','57','269','242','682','506','385','53','90392','357','42','45','253','1809','1809','593','20','503','240','291','372','251','500','298','679','358','33','594','689','241','220','7880','49','233','350','30','299','1473','590','671','502','224','245','592','509','504','852','36','354','91','62','98','964','353','972','39','1876','81','962','7','254','686','850','82','965','996','856','371','961','266','231','218','417','370','352','853','389','261','265','60','960','223','356','692','596','222','269','52','691','373','377','976','1664','212','258','95','264','674','977','31','687','64','505','227','234','683','672','670','47','968','680','507','675','595','51','63','48','351','1787','974','262','40','7','250','378','239','966','221','381','248','232','65','421','386','677','252','27','34','94','290','1869','1758','249','597','268','46','41','963','886','7','66','228','676','1868','216','90','7','993','1649','688','256','44','380','971','598','1','7','678','379','58','84','84','84','681','969','967','260','263']

@youssedmessaoudi
Copy link

<select class="country-code" id="countryCode" name="country_code">
    <option value="">Code Area</option>
    <option data-countryCode="DZ" value="213">(+213)</option>
    <option data-countryCode="AD" value="376">(+376)</option>
    <option data-countryCode="AO" value="244">(+244)</option>
    <option data-countryCode="AI" value="1264">(+1264)</option>
    <option data-countryCode="AG" value="1268">(+1268)</option>
    <option data-countryCode="AR" value="54">(+54)</option>
    <option data-countryCode="AM" value="374">(+374)</option>
    <option data-countryCode="AW" value="297">(+297)</option>
    <option data-countryCode="AU" value="61">(+61)</option>
    <option data-countryCode="AT" value="43">(+43)</option>
    <option data-countryCode="AZ" value="994">(+994)</option>
    <option data-countryCode="BS" value="1242">(+1242)</option>
    <option data-countryCode="BH" value="973">(+973)</option>
    <option data-countryCode="BD" value="880">(+880)</option>
    <option data-countryCode="BB" value="1246">(+1246)</option>
    <option data-countryCode="BY" value="375">(+375)</option>
    <option data-countryCode="BE" value="32">(+32)</option>
    <option data-countryCode="BZ" value="501">(+501)</option>
    <option data-countryCode="BJ" value="229">(+229)</option>
    <option data-countryCode="BM" value="1441">(+1441)</option>
    <option data-countryCode="BT" value="975">(+975)</option>
    <option data-countryCode="BO" value="591">(+591)</option>
    <option data-countryCode="BA" value="387">(+387)</option>
    <option data-countryCode="BW" value="267">(+267)</option>
    <option data-countryCode="BR" value="55">(+55)</option>
    <option data-countryCode="BN" value="673">(+673)</option>
    <option data-countryCode="BG" value="359">(+359)</option>
    <option data-countryCode="BF" value="226">(+226)</option>
    <option data-countryCode="BI" value="257">(+257)</option>
    <option data-countryCode="KH" value="855">(+855)</option>
    <option data-countryCode="CM" value="237">(+237)</option>
    <option data-countryCode="CA" value="1">(+1)</option>
    <option data-countryCode="CV" value="238">(+238)</option>
    <option data-countryCode="KY" value="1345">(+1345)</option>
    <option data-countryCode="CF" value="236">(+236)</option>
    <option data-countryCode="CL" value="56">(+56)</option>
    <option data-countryCode="CN" value="86">(+86)</option>
    <option data-countryCode="CO" value="57">(+57)</option>
    <option data-countryCode="KM" value="269">(+269)</option>
    <option data-countryCode="CG" value="242">(+242)</option>
    <option data-countryCode="CK" value="682">(+682)</option>
    <option data-countryCode="CR" value="506">(+506)</option>
    <option data-countryCode="HR" value="385">(+385)</option>
    <option data-countryCode="CU" value="53">(+53)</option>
    <option data-countryCode="CY" value="90392">(+90392)</option>
    <option data-countryCode="CY" value="357">(+357)</option>
    <option data-countryCode="CZ" value="42">(+42)</option>
    <option data-countryCode="DK" value="45">(+45)</option>
    <option data-countryCode="DJ" value="253">(+253)</option>
    <option data-countryCode="DM" value="1809">(+1809)</option>
    <option data-countryCode="DO" value="1809">(+1809)</option>
    <option data-countryCode="EC" value="593">(+593)</option>
    <option data-countryCode="EG" value="20">(+20)</option>
    <option data-countryCode="SV" value="503">(+503)</option>
    <option data-countryCode="GQ" value="240">(+240)</option>
    <option data-countryCode="ER" value="291">(+291)</option>
    <option data-countryCode="EE" value="372">(+372)</option>
    <option data-countryCode="ET" value="251">(+251)</option>
    <option data-countryCode="FK" value="500">(+500)</option>
    <option data-countryCode="FO" value="298">(+298)</option>
    <option data-countryCode="FJ" value="679">(+679)</option>
    <option data-countryCode="FI" value="358">(+358)</option>
    <option data-countryCode="FR" value="33">(+33)</option>
    <option data-countryCode="GF" value="594">(+594)</option>
    <option data-countryCode="PF" value="689">(+689)</option>
    <option data-countryCode="GA" value="241">(+241)</option>
    <option data-countryCode="GM" value="220">(+220)</option>
    <option data-countryCode="GE" value="7880">(+7880)</option>
    <option data-countryCode="DE" value="49">(+49)</option>
    <option data-countryCode="GH" value="233">(+233)</option>
    <option data-countryCode="GI" value="350">(+350)</option>
    <option data-countryCode="GR" value="30">(+30)</option>
    <option data-countryCode="GL" value="299">(+299)</option>
    <option data-countryCode="GD" value="1473">(+1473)</option>
    <option data-countryCode="GP" value="590">(+590)</option>
    <option data-countryCode="GU" value="671">(+671)</option>
    <option data-countryCode="GT" value="502">(+502)</option>
    <option data-countryCode="GN" value="224">(+224)</option>
    <option data-countryCode="GW" value="245">(+245)</option>
    <option data-countryCode="GY" value="592">(+592)</option>
    <option data-countryCode="HT" value="509">(+509)</option>
    <option data-countryCode="HN" value="504">(+504)</option>
    <option data-countryCode="HK" value="852">(+852)</option>
    <option data-countryCode="HU" value="36">(+36)</option>
    <option data-countryCode="IS" value="354">(+354)</option>
    <option data-countryCode="IN" value="91">(+91)</option>
    <option data-countryCode="ID" value="62">(+62)</option>
    <option data-countryCode="IR" value="98">(+98)</option>
    <option data-countryCode="IQ" value="964">(+964)</option>
    <option data-countryCode="IE" value="353">(+353)</option>
    <option data-countryCode="IL" value="972">(+972)</option>
    <option data-countryCode="IT" value="39">(+39)</option>
    <option data-countryCode="JM" value="1876">(+1876)</option>
    <option data-countryCode="JP" value="81">(+81)</option>
    <option data-countryCode="JO" value="962">(+962)</option>
    <option data-countryCode="KZ" value="7">(+7)</option>
    <option data-countryCode="KE" value="254">(+254)</option>
    <option data-countryCode="KI" value="686">(+686)</option>
    <option data-countryCode="KP" value="850">(+850)</option>
    <option data-countryCode="KR" value="82">(+82)</option>
    <option data-countryCode="KW" value="965">(+965)</option>
    <option data-countryCode="KG" value="996">(+996)</option>
    <option data-countryCode="LA" value="856">(+856)</option>
    <option data-countryCode="LV" value="371">(+371)</option>
    <option data-countryCode="LB" value="961">(+961)</option>
    <option data-countryCode="LS" value="266">(+266)</option>
    <option data-countryCode="LR" value="231">(+231)</option>
    <option data-countryCode="LY" value="218">(+218)</option>
    <option data-countryCode="LI" value="417">(+417)</option>
    <option data-countryCode="LT" value="370">(+370)</option>
    <option data-countryCode="LU" value="352">(+352)</option>
    <option data-countryCode="MO" value="853">(+853)</option>
    <option data-countryCode="MK" value="389">(+389)</option>
    <option data-countryCode="MG" value="261">(+261)</option>
    <option data-countryCode="MW" value="265">(+265)</option>
    <option data-countryCode="MY" value="60">(+60)</option>
    <option data-countryCode="MV" value="960">(+960)</option>
    <option data-countryCode="ML" value="223">(+223)</option>
    <option data-countryCode="MT" value="356">(+356)</option>
    <option data-countryCode="MH" value="692">(+692)</option>
    <option data-countryCode="MQ" value="596">(+596)</option>
    <option data-countryCode="MR" value="222">(+222)</option>
    <option data-countryCode="YT" value="269">(+269)</option>
    <option data-countryCode="MX" value="52">(+52)</option>
    <option data-countryCode="FM" value="691">(+691)</option>
    <option data-countryCode="MD" value="373">(+373)</option>
    <option data-countryCode="MC" value="377">(+377)</option>
    <option data-countryCode="MN" value="976">(+976)</option>
    <option data-countryCode="MS" value="1664">(+1664)</option>
    <option data-countryCode="MA" value="212">(+212)</option>
    <option data-countryCode="MZ" value="258">(+258)</option>
    <option data-countryCode="MN" value="95">(+95)</option>
    <option data-countryCode="NA" value="264">(+264)</option>
    <option data-countryCode="NR" value="674">(+674)</option>
    <option data-countryCode="NP" value="977">(+977)</option>
    <option data-countryCode="NL" value="31">(+31)</option>
    <option data-countryCode="NC" value="687">(+687)</option>
    <option data-countryCode="NZ" value="64">(+64)</option>
    <option data-countryCode="NI" value="505">(+505)</option>
    <option data-countryCode="NE" value="227">(+227)</option>
    <option data-countryCode="NG" value="234">(+234)</option>
    <option data-countryCode="NU" value="683">(+683)</option>
    <option data-countryCode="NF" value="672">(+672)</option>
    <option data-countryCode="NP" value="670">(+670)</option>
    <option data-countryCode="NO" value="47">(+47)</option>
    <option data-countryCode="OM" value="968">(+968)</option>
    <option data-countryCode="PW" value="680">(+680)</option>
    <option data-countryCode="PA" value="507">(+507)</option>
    <option data-countryCode="PG" value="675">(+675)</option>
    <option data-countryCode="PY" value="595">(+595)</option>
    <option data-countryCode="PE" value="51">(+51)</option>
    <option data-countryCode="PH" value="63">(+63)</option>
    <option data-countryCode="PL" value="48">(+48)</option>
    <option data-countryCode="PT" value="351">(+351)</option>
    <option data-countryCode="PR" value="1787">(+1787)</option>
    <option data-countryCode="QA" value="974">(+974)</option>
    <option data-countryCode="RE" value="262">(+262)</option>
    <option data-countryCode="RO" value="40">(+40)</option>
    <option data-countryCode="RU" value="7">(+7)</option>
    <option data-countryCode="RW" value="250">(+250)</option>
    <option data-countryCode="SM" value="378">(+378)</option>
    <option data-countryCode="ST" value="239">(+239)</option>
    <option data-countryCode="SA" value="966">(+966)</option>
    <option data-countryCode="SN" value="221">(+221)</option>
    <option data-countryCode="CS" value="381">(+381)</option>
    <option data-countryCode="SC" value="248">(+248)</option>
    <option data-countryCode="SL" value="232">(+232)</option>
    <option data-countryCode="SG" value="65">(+65)</option>
    <option data-countryCode="SK" value="421">(+421)</option>
    <option data-countryCode="SI" value="386">(+386)</option>
    <option data-countryCode="SB" value="677">(+677)</option>
    <option data-countryCode="SO" value="252">(+252)</option>
    <option data-countryCode="ZA" value="27">(+27)</option>
    <option data-countryCode="ES" value="34">(+34)</option>
    <option data-countryCode="LK" value="94">(+94)</option>
    <option data-countryCode="SH" value="290">(+290)</option>
    <option data-countryCode="KN" value="1869">(+1869)</option>
    <option data-countryCode="SC" value="1758">(+1758)</option>
    <option data-countryCode="SD" value="249">(+249)</option>
    <option data-countryCode="SR" value="597">(+597)</option>
    <option data-countryCode="SZ" value="268">(+268)</option>
    <option data-countryCode="SE" value="46">(+46)</option>
    <option data-countryCode="CH" value="41">(+41)</option>
    <option data-countryCode="SI" value="963">(+963)</option>
    <option data-countryCode="TW" value="886">(+886)</option>
    <option data-countryCode="TJ" value="7">(+7)</option>
    <option data-countryCode="TH" value="66">(+66)</option>
    <option data-countryCode="TG" value="228">(+228)</option>
    <option data-countryCode="TO" value="676">(+676)</option>
    <option data-countryCode="TT" value="1868">(+1868)</option>
    <option data-countryCode="TN" value="216">(+216)</option>
    <option data-countryCode="TR" value="90">(+90)</option>
    <option data-countryCode="TM" value="7">(+7)</option>
    <option data-countryCode="TM" value="993">(+993)</option>
    <option data-countryCode="TC" value="1649">(+1649)</option>
    <option data-countryCode="TV" value="688">(+688)</option>
    <option data-countryCode="UG" value="256">(+256)</option>
    <option data-countryCode="GB" value="44">(+44)</option>
    <option data-countryCode="UA" value="380">(+380)</option>
    <option data-countryCode="AE" value="971">(+971)</option>
    <option data-countryCode="UY" value="598">(+598)</option>
    <option data-countryCode="US" value="1">(+1)</option>
    <option data-countryCode="UZ" value="7">(+7)</option>
    <option data-countryCode="VU" value="678">(+678)</option>
    <option data-countryCode="VA" value="379">(+379)</option>
    <option data-countryCode="VE" value="58">(+58)</option>
    <option data-countryCode="VN" value="84">(+84)</option>
    <option data-countryCode="VG" value="84">(+1284)</option>
    <option data-countryCode="VI" value="84">(+1340)</option>
    <option data-countryCode="WF" value="681">(+681)</option>
    <option data-countryCode="YE" value="969">(+969)</option>
    <option data-countryCode="YE" value="967">(+967)</option>
    <option data-countryCode="ZM" value="260">(+260)</option>
    <option data-countryCode="ZW" value="263">(+263)</option>
</select>

<script>
const select = document.getElementById("countryCode"); // Get the select element
const phoneCodes = [];

for (let i = 0; i < select.options.length; i++) {
    const option = select.options[i];
    phoneCodes.push("'"+option.value+"'");
}

// Convert the array to a comma-separated string
const phoneCodesString = phoneCodes.join(",");

// Send the data to the PHP script
fetch("t.php", {
    method: "POST",
    body: new URLSearchParams({ phoneCodes: phoneCodesString }),
})
.then(response => response.text())
.then(data => {
    console.log(data); // Display the response from the server
})
.catch(error => {
    console.error("Error:", error);
});


`</script>```

@youssedmessaoudi
Copy link

<?php
if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $phoneCodes = `$_POST["phoneCodes"];`
    
    // Create a text file and write the phone codes to it
    $file = fopen("phone_codes.txt", "w");
    fwrite($file, $phoneCodes);
    fclose($file);
    
    echo "File saved successfully.";
} else {
    echo "Invalid request.";
}
?>

@v0ff4k
Copy link

v0ff4k commented Nov 12, 2023

@mkhoussid
Copy link

@v0ff4k This does exactly what the gist says it does. If '7' returns more than one country, then it's fine. In the dropdown, let the users choose themselves what exactly they need, Kazakhstan or Russia.

check my recent post !

No one cares

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment