首頁 > php教程 > PHP源码 > 国家代码查询函数之PHP版

国家代码查询函数之PHP版

PHP中文网
發布: 2016-05-25 17:15:46
原創
1477 人瀏覽過

国家代码查询函数之PHP版

这个函数能把两个英文字母表示的国家代码转化成中文的国家名称,它只接收一个参数,即英文表示的国家代码(非大小写敏感),当这个代码不存在时,函数返回null。该函数一共收录了245个国家,应该是很完整的了。

<?php
function transCountryCode($code) {
    $index=array(&#39;AA&#39;=>&#39;阿鲁巴&#39;,
    &#39;AD&#39;=>&#39;安道尔&#39;,
    &#39;AE&#39;=>&#39;阿联酋&#39;,
    &#39;AF&#39;=>&#39;阿富汗&#39;,
    &#39;AG&#39;=>&#39;安提瓜和巴布达&#39;,
    &#39;AL&#39;=>&#39;阿尔巴尼亚&#39;,
    &#39;AM&#39;=>&#39;亚美尼亚&#39;,
    &#39;AN&#39;=>&#39;荷属安德列斯&#39;,
    &#39;AO&#39;=>&#39;安哥拉&#39;,
    &#39;AQ&#39;=>&#39;南极洲&#39;,
    &#39;AR&#39;=>&#39;阿根廷&#39;,
    &#39;AS&#39;=>&#39;东萨摩亚&#39;,
    &#39;AT&#39;=>&#39;奥地利&#39;,
    &#39;AU&#39;=>&#39;澳大利亚&#39;,
    &#39;AZ&#39;=>&#39;阿塞拜疆&#39;,
    &#39;Av&#39;=>&#39;安圭拉岛&#39;,
    &#39;BA&#39;=>&#39;波黑&#39;,
    &#39;BB&#39;=>&#39;巴巴多斯&#39;,
    &#39;BD&#39;=>&#39;孟加拉&#39;,
    &#39;BE&#39;=>&#39;比利时&#39;,
    &#39;BF&#39;=>&#39;巴哈马&#39;,
    &#39;BF&#39;=>&#39;布基纳法索&#39;,
    &#39;BG&#39;=>&#39;保加利亚&#39;,
    &#39;BH&#39;=>&#39;巴林&#39;,
    &#39;BI&#39;=>&#39;布隆迪&#39;,
    &#39;BJ&#39;=>&#39;贝宁&#39;,
    &#39;BM&#39;=>&#39;百慕大&#39;,
    &#39;BN&#39;=>&#39;文莱布鲁萨兰&#39;,
    &#39;BO&#39;=>&#39;玻利维亚&#39;,
    &#39;BR&#39;=>&#39;巴西&#39;,
    &#39;BS&#39;=>&#39;巴哈马&#39;,
    &#39;BT&#39;=>&#39;不丹&#39;,
    &#39;BV&#39;=>&#39;布韦岛&#39;,
    &#39;BW&#39;=>&#39;博茨瓦纳&#39;,
    &#39;BY&#39;=>&#39;白俄罗斯&#39;,
    &#39;BZ&#39;=>&#39;伯里兹&#39;,
    &#39;CA&#39;=>&#39;加拿大&#39;,
    &#39;CB&#39;=>&#39;柬埔寨&#39;,
    &#39;CC&#39;=>&#39;可可斯群岛&#39;,
    &#39;CD&#39;=>&#39;刚果&#39;,
    &#39;CF&#39;=>&#39;中非&#39;,
    &#39;CG&#39;=>&#39;刚果&#39;,
    &#39;CH&#39;=>&#39;瑞士&#39;,
    &#39;CI&#39;=>&#39;象牙海岸&#39;,
    &#39;CK&#39;=>&#39;库克群岛&#39;,
    &#39;CL&#39;=>&#39;智利&#39;,
    &#39;CM&#39;=>&#39;喀麦隆&#39;,
    &#39;CN&#39;=>&#39;中国&#39;,
    &#39;CO&#39;=>&#39;哥伦比亚&#39;,
    &#39;CR&#39;=>&#39;哥斯达黎加&#39;,
    &#39;CS&#39;=>&#39;捷克斯洛伐克&#39;,
    &#39;CU&#39;=>&#39;古巴&#39;,
    &#39;CV&#39;=>&#39;佛得角&#39;,
    &#39;CX&#39;=>&#39;圣诞岛&#39;,
    &#39;CY&#39;=>&#39;塞普路斯&#39;,
    &#39;CZ&#39;=>&#39;捷克&#39;,
    &#39;DE&#39;=>&#39;德国&#39;,
    &#39;DJ&#39;=>&#39;吉布提&#39;,
    &#39;DK&#39;=>&#39;丹麦&#39;,
    &#39;DM&#39;=>&#39;多米尼加共和国&#39;,
    &#39;DO&#39;=>&#39;多米尼加联邦&#39;,
    &#39;DZ&#39;=>&#39;阿尔及利亚&#39;,
    &#39;EC&#39;=>&#39;厄瓜多尔&#39;,
    &#39;EE&#39;=>&#39;爱沙尼亚&#39;,
    &#39;EG&#39;=>&#39;埃及&#39;,
    &#39;EH&#39;=>&#39;西撒哈拉&#39;,
    &#39;ER&#39;=>&#39;厄立特里亚&#39;,
    &#39;ES&#39;=>&#39;西班牙&#39;,
    &#39;ET&#39;=>&#39;埃塞俄比亚&#39;,
    &#39;FI&#39;=>&#39;芬兰&#39;,
    &#39;FJ&#39;=>&#39;斐济&#39;,
    &#39;FK&#39;=>&#39;福兰克群岛&#39;,
    &#39;FM&#39;=>&#39;米克罗尼西亚&#39;,
    &#39;FO&#39;=>&#39;法罗群岛&#39;,
    &#39;FR&#39;=>&#39;法国&#39;,
    &#39;FX&#39;=>&#39;法国-主教区&#39;,
    &#39;GA&#39;=>&#39;加蓬&#39;,
    &#39;GB&#39;=>&#39;英国&#39;,
    &#39;GD&#39;=>&#39;格林纳达&#39;,
    &#39;GE&#39;=>&#39;格鲁吉亚&#39;,
    &#39;GF&#39;=>&#39;法属圭亚那&#39;,
    &#39;GH&#39;=>&#39;加纳&#39;,
    &#39;GI&#39;=>&#39;直布罗陀&#39;,
    &#39;GL&#39;=>&#39;格陵兰岛&#39;,
    &#39;GM&#39;=>&#39;冈比亚&#39;,
    &#39;GN&#39;=>&#39;几内亚&#39;,
    &#39;GP&#39;=>&#39;法属德洛普群岛&#39;,
    &#39;GQ&#39;=>&#39;赤道几内亚&#39;,
    &#39;GR&#39;=>&#39;希腊&#39;,
    &#39;GS&#39;=>&#39;S. Georgia and S. Sandwich Isls.&#39;,
    &#39;GT&#39;=>&#39;危地马拉&#39;,
    &#39;GU&#39;=>&#39;关岛&#39;,
    &#39;GW&#39;=>&#39;几内亚比绍&#39;,
    &#39;GY&#39;=>&#39;圭亚那&#39;,
    &#39;HK&#39;=>&#39;中国香港特区&#39;,
    &#39;HM&#39;=>&#39;赫德和麦克唐纳群岛&#39;,
    &#39;HN&#39;=>&#39;洪都拉斯&#39;,
    &#39;HR&#39;=>&#39;克罗地亚&#39;,
    &#39;HT&#39;=>&#39;海地&#39;,
    &#39;HU&#39;=>&#39;匈牙利&#39;,
    &#39;ID&#39;=>&#39;印度尼西亚&#39;,
    &#39;IE&#39;=>&#39;爱尔兰&#39;,
    &#39;IL&#39;=>&#39;以色列&#39;,
    &#39;IN&#39;=>&#39;印度&#39;,
    &#39;IO&#39;=>&#39;英属印度洋领地&#39;,
    &#39;IQ&#39;=>&#39;伊拉克&#39;,
    &#39;IR&#39;=>&#39;伊朗&#39;,
    &#39;IS&#39;=>&#39;冰岛&#39;,
    &#39;IT&#39;=>&#39;意大利&#39;,
    &#39;JM&#39;=>&#39;牙买加&#39;,
    &#39;JO&#39;=>&#39;约旦&#39;,
    &#39;JP&#39;=>&#39;日本&#39;,
    &#39;KE&#39;=>&#39;肯尼亚&#39;,
    &#39;KG&#39;=>&#39;吉尔吉斯斯坦&#39;,
    &#39;KH&#39;=>&#39;柬埔寨&#39;,
    &#39;KI&#39;=>&#39;基里巴斯&#39;,
    &#39;KM&#39;=>&#39;科摩罗&#39;,
    &#39;KN&#39;=>&#39;圣基茨和尼维斯&#39;,
    &#39;KP&#39;=>&#39;韩国&#39;,
    &#39;KR&#39;=>&#39;朝鲜&#39;,
    &#39;KW&#39;=>&#39;科威特&#39;,
    &#39;KY&#39;=>&#39;开曼群岛&#39;,
    &#39;KZ&#39;=>&#39;哈萨克斯坦&#39;,
    &#39;LA&#39;=>&#39;老挝&#39;,
    &#39;LB&#39;=>&#39;黎巴嫩&#39;,
    &#39;LC&#39;=>&#39;圣卢西亚&#39;,
    &#39;LI&#39;=>&#39;列支顿士登&#39;,
    &#39;LK&#39;=>&#39;斯里兰卡&#39;,
    &#39;LR&#39;=>&#39;利比里亚&#39;,
    &#39;LS&#39;=>&#39;莱索托&#39;,
    &#39;LT&#39;=>&#39;立陶宛&#39;,
    &#39;LU&#39;=>&#39;卢森堡&#39;,
    &#39;LV&#39;=>&#39;拉托维亚&#39;,
    &#39;LY&#39;=>&#39;利比亚&#39;,
    &#39;MA&#39;=>&#39;摩洛哥&#39;,
    &#39;MC&#39;=>&#39;摩纳哥&#39;,
    &#39;MD&#39;=>&#39;摩尔多瓦&#39;,
    &#39;MG&#39;=>&#39;马达加斯加&#39;,
    &#39;MH&#39;=>&#39;马绍尔群岛&#39;,
    &#39;MK&#39;=>&#39;马其顿&#39;,
    &#39;ML&#39;=>&#39;马里&#39;,
    &#39;MM&#39;=>&#39;缅甸&#39;,
    &#39;MN&#39;=>&#39;蒙古&#39;,
    &#39;MO&#39;=>&#39;中国澳门特区&#39;,
    &#39;MP&#39;=>&#39;北马里亚纳群岛&#39;,
    &#39;MQ&#39;=>&#39;法属马提尼克群岛&#39;,
    &#39;MR&#39;=>&#39;毛里塔尼亚&#39;,
    &#39;MS&#39;=>&#39;蒙塞拉特岛&#39;,
    &#39;MT&#39;=>&#39;马耳他&#39;,
    &#39;MU&#39;=>&#39;毛里求斯&#39;,
    &#39;MV&#39;=>&#39;马尔代夫&#39;,
    &#39;MW&#39;=>&#39;马拉维&#39;,
    &#39;MX&#39;=>&#39;墨西哥&#39;,
    &#39;MY&#39;=>&#39;马来西亚&#39;,
    &#39;MZ&#39;=>&#39;莫桑比克&#39;,
    &#39;NA&#39;=>&#39;纳米比亚&#39;,
    &#39;NC&#39;=>&#39;新卡里多尼亚&#39;,
    &#39;NE&#39;=>&#39;尼日尔&#39;,
    &#39;NF&#39;=>&#39;诺福克岛&#39;,
    &#39;NG&#39;=>&#39;尼日利亚&#39;,
    &#39;NI&#39;=>&#39;尼加拉瓜&#39;,
    &#39;NL&#39;=>&#39;荷兰&#39;,
    &#39;NO&#39;=>&#39;挪威&#39;,
    &#39;NP&#39;=>&#39;尼泊尔&#39;,
    &#39;NR&#39;=>&#39;瑙鲁&#39;,
    &#39;NT&#39;=>&#39;中立区(沙特-伊拉克间)&#39;,
    &#39;NU&#39;=>&#39;纽爱&#39;,
    &#39;NZ&#39;=>&#39;新西兰&#39;,
    &#39;OM&#39;=>&#39;阿曼&#39;,
    &#39;PA&#39;=>&#39;巴拿马&#39;,
    &#39;PE&#39;=>&#39;秘鲁&#39;,
    &#39;PF&#39;=>&#39;法属玻里尼西亚&#39;,
    &#39;PG&#39;=>&#39;巴布亚新几内亚&#39;,
    &#39;PH&#39;=>&#39;菲律宾&#39;,
    &#39;PK&#39;=>&#39;巴基斯坦&#39;,
    &#39;PL&#39;=>&#39;波兰&#39;,
    &#39;PM&#39;=>&#39;圣皮艾尔和密克隆群岛&#39;,
    &#39;PN&#39;=>&#39;皮特克恩岛&#39;,
    &#39;PR&#39;=>&#39;波多黎各&#39;,
    &#39;PT&#39;=>&#39;葡萄牙&#39;,
    &#39;PW&#39;=>&#39;帕劳&#39;,
    &#39;PY&#39;=>&#39;巴拉圭&#39;,
    &#39;QA&#39;=>&#39;卡塔尔&#39;,
    &#39;RE&#39;=>&#39;法属尼留旺岛&#39;,
    &#39;RO&#39;=>&#39;罗马尼亚&#39;,
    &#39;RU&#39;=>&#39;俄罗斯&#39;,
    &#39;RW&#39;=>&#39;卢旺达&#39;,
    &#39;SA&#39;=>&#39;沙特阿拉伯&#39;,
    &#39;SC&#39;=>&#39;塞舌尔&#39;,
    &#39;SD&#39;=>&#39;苏丹&#39;,
    &#39;SE&#39;=>&#39;瑞典&#39;,
    &#39;SG&#39;=>&#39;新加坡&#39;,
    &#39;SH&#39;=>&#39;圣赫勒拿&#39;,
    &#39;SI&#39;=>&#39;斯罗文尼亚&#39;,
    &#39;SJ&#39;=>&#39;斯瓦尔巴特和扬马延岛&#39;,
    &#39;SK&#39;=>&#39;斯洛伐克&#39;,
    &#39;SL&#39;=>&#39;塞拉利昂&#39;,
    &#39;SM&#39;=>&#39;圣马力诺&#39;,
    &#39;SN&#39;=>&#39;塞内加尔&#39;,
    &#39;SO&#39;=>&#39;索马里&#39;,
    &#39;SR&#39;=>&#39;苏里南&#39;,
    &#39;ST&#39;=>&#39;圣多美和普林西比&#39;,
    &#39;SU&#39;=>&#39;前苏联&#39;,
    &#39;SV&#39;=>&#39;萨尔瓦多&#39;,
    &#39;SY&#39;=>&#39;叙利亚&#39;,
    &#39;SZ&#39;=>&#39;斯威士兰&#39;,
    &#39;Sb&#39;=>&#39;所罗门群岛&#39;,
    &#39;TC&#39;=>&#39;特克斯和凯科斯群岛&#39;,
    &#39;TD&#39;=>&#39;乍得&#39;,
    &#39;TF&#39;=>&#39;法国南部领地&#39;,
    &#39;TG&#39;=>&#39;多哥&#39;,
    &#39;TH&#39;=>&#39;泰国&#39;,
    &#39;TJ&#39;=>&#39;塔吉克斯坦&#39;,
    &#39;TK&#39;=>&#39;托克劳群岛&#39;,
    &#39;TM&#39;=>&#39;土库曼斯坦&#39;,
    &#39;TN&#39;=>&#39;突尼斯&#39;,
    &#39;TO&#39;=>&#39;汤加&#39;,
    &#39;TP&#39;=>&#39;东帝汶&#39;,
    &#39;TR&#39;=>&#39;土尔其&#39;,
    &#39;TT&#39;=>&#39;特立尼达和多巴哥&#39;,
    &#39;TV&#39;=>&#39;图瓦卢&#39;,
    &#39;TW&#39;=>&#39;中国台湾省&#39;,
    &#39;TZ&#39;=>&#39;坦桑尼亚&#39;,
    &#39;UA&#39;=>&#39;乌克兰&#39;,
    &#39;UG&#39;=>&#39;乌干达&#39;,
    &#39;UK&#39;=>&#39;英国&#39;,
    &#39;UM&#39;=>&#39;美国海外领地&#39;,
    &#39;US&#39;=>&#39;美国&#39;,
    &#39;UY&#39;=>&#39;乌拉圭&#39;,
    &#39;UZ&#39;=>&#39;乌兹别克斯坦&#39;,
    &#39;VA&#39;=>&#39;梵蒂岗&#39;,
    &#39;VC&#39;=>&#39;圣文森特和格陵纳丁斯&#39;,
    &#39;VE&#39;=>&#39;委内瑞拉&#39;,
    &#39;VG&#39;=>&#39;英属维京群岛&#39;,
    &#39;VI&#39;=>&#39;美属维京群岛&#39;,
    &#39;VN&#39;=>&#39;越南&#39;,
    &#39;VU&#39;=>&#39;瓦努阿鲁&#39;,
    &#39;WF&#39;=>&#39;瓦里斯和福图纳群岛&#39;,
    &#39;WS&#39;=>&#39;西萨摩亚&#39;,
    &#39;YE&#39;=>&#39;也门&#39;,
    &#39;YT&#39;=>&#39;马约特岛&#39;,
    &#39;YU&#39;=>&#39;南斯拉夫&#39;,
    &#39;ZA&#39;=>&#39;南非&#39;,
    &#39;ZM&#39;=>&#39;赞比亚&#39;,
    &#39;ZR&#39;=>&#39;扎伊尔&#39;,
    &#39;ZW&#39;=>&#39;津巴布韦&#39;);
    $code=strtoupper($code);
    $name=$index[$code];
    if (empty($name)) {
        return null;
    }
    return $name;
}
?>
登入後複製

                   

 以上就是国家代码查询函数之PHP版的内容,更多相关内容请关注PHP中文网(www.php.cn)!

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板