选择国家和城市

发布于 2024-11-02 18:36:52 字数 162 浏览 1 评论 0原文

是否有包含国家和城市数组的 php 文件,类似于:

$country[] = "Albania";
$country[] = "Algeria";

与城市相同?或者是否有其他可能更好的解决方案来向用户显示国家/地区并让他们选择?谢谢。

Are there php file with array with countries and cities, something like that:

$country[] = "Albania";
$country[] = "Algeria";

And the same with cities? Or are there any other, maybe better, solutions for showing countries for users and give them to select? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

对风讲故事 2024-11-09 18:36:52

是的,GeoNames

$countries = json_decode(file_get_contents('http://www.geonames.org/countryInfoJSON'), true);

对于城市,您需要使用边界框坐标(可从之前的请求结果)和 Cities 方法,还支持本地化大多数语言使用 lang 查询字符串。

编辑:您可能想要缓存(或下载)这些结果以避免GeoNames 服务器超载。

Yes, GeoNames:

$countries = json_decode(file_get_contents('http://www.geonames.org/countryInfoJSON'), true);

For cities you need to use the bounding box coordinates (available from the previous request result) and the Cities method, localization is also supported for most languages using the lang query string.

EDIT: You probably want to cache (or download) these results to avoid overloading GeoNames server.

梦屿孤独相伴 2024-11-09 18:36:52

PHP 中没有内置类似的东西。您必须找到一个国家/地区列表,然后使用 PHP 解析它或将其存储在 MySQL 表中。

There isn't something like this built into PHP. You'll have to find a country list and either parse it with PHP or store it in a MySQL table.

音栖息无 2024-11-09 18:36:52

如果您不想使用数据库,最好的方法是使用网络服务为您提供列表
例如:这个

Your best approach if you don't want to use a database is to use a webservice to provide you with a list
like: This one

残月升风 2024-11-09 18:36:52

国家/地区

我刚刚从数据库中导出此列表。

$countries = array(
  1 => "Afghanistan",
  2 => "Albania",
  3 => "Algeria",
  4 => "American Samoa",
  5 => "Andorra",
  6 => "Angola",
  7 => "Anguilla",
  8 => "Antarctica",
  9 => "Antigua & Barbuda",
  10 => "Argentina",
  11 => "Armenia",
  12 => "Aruba",
  13 => "Australia",
  14 => "Austria",
  15 => "Azerbaijan",
  16 => "Bahamas",
  17 => "Bahrain",
  18 => "Bangladesh",
  19 => "Barbados",
  20 => "Belarus",
  21 => "Belgium",
  22 => "Belize",
  23 => "Benin",
  24 => "Bermuda",
  25 => "Bhutan",
  26 => "Bolivia",
  27 => "Bosnia & Herzegovina",
  28 => "Botswana",
  29 => "Bouvet Island",
  30 => "Brazil",
  31 => "British Indian Ocean Territory",
  32 => "Brunei",
  33 => "Bulgaria",
  34 => "Burkina Faso",
  35 => "Burundi",
  36 => "Cambodia",
  37 => "Cameroon",
  38 => "Canada",
  39 => "Cape Verde",
  40 => "Cayman Islands",
  41 => "Central African Republic",
  42 => "Chad",
  43 => "Chile",
  44 => "China",
  45 => "Chinese Taipei/Taiwan",
  46 => "Colombia",
  47 => "Comoros",
  48 => "Congo",
  49 => "Congo,DR",
  50 => "Cook Islands",
  51 => "Costa Rica",
  52 => "Cote d' Ivoire",
  53 => "Croatia",
  54 => "Cuba",
  55 => "Cyprus",
  56 => "Czech Republic",
  57 => "Denmark",
  58 => "Djibouti",
  59 => "Dominica",
  60 => "Dominican Republic",
  61 => "Ecuador",
  62 => "Egypt",
  63 => "El Salvador",
  64 => "Equatorial Guinea",
  65 => "Eritrea",
  66 => "Estonia",
  67 => "Ethiopia",
  68 => "Falkland Islands (Malvinas)",
  69 => "Faroe Islands",
  70 => "Fiji",
  71 => "Finland",
  72 => "France",
  73 => "French Guiana",
  74 => "French Polynesia",
  75 => "Gabon",
  76 => "Gambia",
  77 => "Georgia",
  78 => "Germany",
  79 => "Ghana",
  80 => "Gibraltar",
  81 => "Great Britain",
  82 => "Greece",
  83 => "Greenland",
  84 => "Grenada",
  85 => "Guadeloupe",
  86 => "Guam",
  87 => "Guatemala",
  88 => "Guinea",
  89 => "Guinea-Bissau",
  90 => "Guyana",
  91 => "Haiti",
  92 => "Heard Island and McDonald Islands",
  93 => "Honduras",
  94 => "Hong Kong",
  95 => "Hungary",
  96 => "Iceland",
  97 => "India",
  98 => "Indonesia",
  99 => "Iran",
  100 => "Iraq",
  101 => "Ireland",
  102 => "Israel",
  103 => "Italy",
  104 => "Jamaica",
  105 => "Japan",
  106 => "Jordan",
  107 => "Kazakhstan",
  108 => "Kenya",
  109 => "Kiribati",
  110 => "Korea",
  111 => "Kuwait",
  112 => "Kyrgyzstan",
  113 => "Lao",
  114 => "Latvia",
  115 => "Lebanon",
  116 => "Lesotho",
  117 => "Liberia",
  118 => "Libya",
  119 => "Liechtenstein",
  120 => "Lithuania",
  121 => "Luxembourg",
  122 => "Macau",
  123 => "Macedonia, FYR",
  124 => "Madagascar",
  125 => "Malawi",
  126 => "Malaysia",
  127 => "Maldives",
  128 => "Mali",
  129 => "Malta",
  130 => "Marshall Islands",
  131 => "Martinique",
  132 => "Mauritania",
  133 => "Mauritius",
  134 => "Mayotte",
  135 => "Mexico",
  136 => "Micronesia",
  137 => "Moldova",
  138 => "Monaco",
  139 => "Mongolia",
  140 => "Montenegro",
  141 => "Montserrat",
  142 => "Morocco",
  143 => "Mozambique",
  144 => "Myanmar",
  145 => "Namibia",
  146 => "Nauru",
  147 => "Nepal",
  148 => "Netherlands",
  149 => "Netherlands Antilles",
  150 => "New Caledonia",
  151 => "New Zealand",
  152 => "Nicaragua",
  153 => "Niger",
  154 => "Nigeria",
  155 => "Niue",
  156 => "Norfolk Island",
  157 => "North Korea",
  158 => "Northern Mariana Islands",
  159 => "Norway",
  160 => "Oman",
  161 => "Pakistan",
  162 => "Palau",
  163 => "Palestine",
  164 => "Panama",
  165 => "Papua New Guinea",
  166 => "Paraguay",
  167 => "Peru",
  168 => "Philippines",
  169 => "Poland",
  170 => "Portugal",
  171 => "Puerto Rico",
  172 => "Qatar",
  173 => "Reunion",
  174 => "Romania",
  175 => "Russia",
  176 => "Rwanda",
  177 => "Samoa",
  178 => "San Marino",
  179 => "Sao Tome & Principe",
  180 => "Saudi Arabia",
  181 => "Senegal",
  182 => "Serbia",
  183 => "Seychelles",
  184 => "Sierra Leone",
  185 => "Singapore",
  186 => "Slovakia",
  187 => "Slovenia",
  188 => "Solomon Islands",
  189 => "Somalia",
  190 => "South Africa",
  191 => "Spain",
  192 => "Sri Lanka",
  193 => "St.Kitts & Nevis",
  194 => "St.Lucia",
  195 => "St.Vincent & the Grenadines",
  196 => "Sudan",
  197 => "Suriname",
  198 => "Swaziland",
  199 => "Sweden",
  200 => "Switzerland",
  201 => "Syria",
  202 => "Tajikistan",
  203 => "Tanzania",
  204 => "Thailand",
  205 => "Timor-Leste",
  206 => "Togo",
  207 => "Tokelau",
  208 => "Tonga",
  209 => "Trinidad & Tobago",
  210 => "Tunisia",
  211 => "Turkey",
  212 => "Turkmenistan",
  213 => "Turks and Caicos Islands",
  214 => "Tuvalu",
  215 => "Uganda",
  216 => "Ukraine",
  217 => "United Arab Emirates",
  218 => "United States",
  219 => "United States Minor Outlying Islands",
  220 => "Uruguay",
  221 => "Uzbekistan",
  222 => "Vanuatu",
  223 => "Vatican City State",
  224 => "Venezuela",
  225 => "Vietnam",
  226 => "Virgin Islands (UK)",
  227 => "Virgin Islands (USA)",
  228 => "Wallis and Futuna",
  229 => "Yemen",
  230 => "Zambia",
  231 => "Zimbabwe"
}

关于城市,我无能为力。

Countries

I've just exported this list from my database.

$countries = array(
  1 => "Afghanistan",
  2 => "Albania",
  3 => "Algeria",
  4 => "American Samoa",
  5 => "Andorra",
  6 => "Angola",
  7 => "Anguilla",
  8 => "Antarctica",
  9 => "Antigua & Barbuda",
  10 => "Argentina",
  11 => "Armenia",
  12 => "Aruba",
  13 => "Australia",
  14 => "Austria",
  15 => "Azerbaijan",
  16 => "Bahamas",
  17 => "Bahrain",
  18 => "Bangladesh",
  19 => "Barbados",
  20 => "Belarus",
  21 => "Belgium",
  22 => "Belize",
  23 => "Benin",
  24 => "Bermuda",
  25 => "Bhutan",
  26 => "Bolivia",
  27 => "Bosnia & Herzegovina",
  28 => "Botswana",
  29 => "Bouvet Island",
  30 => "Brazil",
  31 => "British Indian Ocean Territory",
  32 => "Brunei",
  33 => "Bulgaria",
  34 => "Burkina Faso",
  35 => "Burundi",
  36 => "Cambodia",
  37 => "Cameroon",
  38 => "Canada",
  39 => "Cape Verde",
  40 => "Cayman Islands",
  41 => "Central African Republic",
  42 => "Chad",
  43 => "Chile",
  44 => "China",
  45 => "Chinese Taipei/Taiwan",
  46 => "Colombia",
  47 => "Comoros",
  48 => "Congo",
  49 => "Congo,DR",
  50 => "Cook Islands",
  51 => "Costa Rica",
  52 => "Cote d' Ivoire",
  53 => "Croatia",
  54 => "Cuba",
  55 => "Cyprus",
  56 => "Czech Republic",
  57 => "Denmark",
  58 => "Djibouti",
  59 => "Dominica",
  60 => "Dominican Republic",
  61 => "Ecuador",
  62 => "Egypt",
  63 => "El Salvador",
  64 => "Equatorial Guinea",
  65 => "Eritrea",
  66 => "Estonia",
  67 => "Ethiopia",
  68 => "Falkland Islands (Malvinas)",
  69 => "Faroe Islands",
  70 => "Fiji",
  71 => "Finland",
  72 => "France",
  73 => "French Guiana",
  74 => "French Polynesia",
  75 => "Gabon",
  76 => "Gambia",
  77 => "Georgia",
  78 => "Germany",
  79 => "Ghana",
  80 => "Gibraltar",
  81 => "Great Britain",
  82 => "Greece",
  83 => "Greenland",
  84 => "Grenada",
  85 => "Guadeloupe",
  86 => "Guam",
  87 => "Guatemala",
  88 => "Guinea",
  89 => "Guinea-Bissau",
  90 => "Guyana",
  91 => "Haiti",
  92 => "Heard Island and McDonald Islands",
  93 => "Honduras",
  94 => "Hong Kong",
  95 => "Hungary",
  96 => "Iceland",
  97 => "India",
  98 => "Indonesia",
  99 => "Iran",
  100 => "Iraq",
  101 => "Ireland",
  102 => "Israel",
  103 => "Italy",
  104 => "Jamaica",
  105 => "Japan",
  106 => "Jordan",
  107 => "Kazakhstan",
  108 => "Kenya",
  109 => "Kiribati",
  110 => "Korea",
  111 => "Kuwait",
  112 => "Kyrgyzstan",
  113 => "Lao",
  114 => "Latvia",
  115 => "Lebanon",
  116 => "Lesotho",
  117 => "Liberia",
  118 => "Libya",
  119 => "Liechtenstein",
  120 => "Lithuania",
  121 => "Luxembourg",
  122 => "Macau",
  123 => "Macedonia, FYR",
  124 => "Madagascar",
  125 => "Malawi",
  126 => "Malaysia",
  127 => "Maldives",
  128 => "Mali",
  129 => "Malta",
  130 => "Marshall Islands",
  131 => "Martinique",
  132 => "Mauritania",
  133 => "Mauritius",
  134 => "Mayotte",
  135 => "Mexico",
  136 => "Micronesia",
  137 => "Moldova",
  138 => "Monaco",
  139 => "Mongolia",
  140 => "Montenegro",
  141 => "Montserrat",
  142 => "Morocco",
  143 => "Mozambique",
  144 => "Myanmar",
  145 => "Namibia",
  146 => "Nauru",
  147 => "Nepal",
  148 => "Netherlands",
  149 => "Netherlands Antilles",
  150 => "New Caledonia",
  151 => "New Zealand",
  152 => "Nicaragua",
  153 => "Niger",
  154 => "Nigeria",
  155 => "Niue",
  156 => "Norfolk Island",
  157 => "North Korea",
  158 => "Northern Mariana Islands",
  159 => "Norway",
  160 => "Oman",
  161 => "Pakistan",
  162 => "Palau",
  163 => "Palestine",
  164 => "Panama",
  165 => "Papua New Guinea",
  166 => "Paraguay",
  167 => "Peru",
  168 => "Philippines",
  169 => "Poland",
  170 => "Portugal",
  171 => "Puerto Rico",
  172 => "Qatar",
  173 => "Reunion",
  174 => "Romania",
  175 => "Russia",
  176 => "Rwanda",
  177 => "Samoa",
  178 => "San Marino",
  179 => "Sao Tome & Principe",
  180 => "Saudi Arabia",
  181 => "Senegal",
  182 => "Serbia",
  183 => "Seychelles",
  184 => "Sierra Leone",
  185 => "Singapore",
  186 => "Slovakia",
  187 => "Slovenia",
  188 => "Solomon Islands",
  189 => "Somalia",
  190 => "South Africa",
  191 => "Spain",
  192 => "Sri Lanka",
  193 => "St.Kitts & Nevis",
  194 => "St.Lucia",
  195 => "St.Vincent & the Grenadines",
  196 => "Sudan",
  197 => "Suriname",
  198 => "Swaziland",
  199 => "Sweden",
  200 => "Switzerland",
  201 => "Syria",
  202 => "Tajikistan",
  203 => "Tanzania",
  204 => "Thailand",
  205 => "Timor-Leste",
  206 => "Togo",
  207 => "Tokelau",
  208 => "Tonga",
  209 => "Trinidad & Tobago",
  210 => "Tunisia",
  211 => "Turkey",
  212 => "Turkmenistan",
  213 => "Turks and Caicos Islands",
  214 => "Tuvalu",
  215 => "Uganda",
  216 => "Ukraine",
  217 => "United Arab Emirates",
  218 => "United States",
  219 => "United States Minor Outlying Islands",
  220 => "Uruguay",
  221 => "Uzbekistan",
  222 => "Vanuatu",
  223 => "Vatican City State",
  224 => "Venezuela",
  225 => "Vietnam",
  226 => "Virgin Islands (UK)",
  227 => "Virgin Islands (USA)",
  228 => "Wallis and Futuna",
  229 => "Yemen",
  230 => "Zambia",
  231 => "Zimbabwe"
}

About cities, I can't help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文