是否有包含国家和城市数组的php文件,类似于:
$country[] = "Albania";
$country[] = "Algeria";
和城市一样吗?或者是否还有其他可能更好的解决方案,用于向用户展示国家并让他们选择?感谢。
答案 0 :(得分:3)
是的,GeoNames:
$countries = json_decode(file_get_contents('http://www.geonames.org/countryInfoJSON'), true);
对于需要使用边界框坐标(可从上一个请求结果获得)和Cities method的城市,使用lang
查询字符串的大多数语言也支持本地化。
编辑:您可能希望缓存(或download)这些结果,以避免GeoNames服务器过载。
答案 1 :(得分:1)
PHP中没有这样的内容。您必须找到一个国家/地区列表,并使用PHP解析它或将其存储在MySQL表中。
答案 2 :(得分:1)
如果您不想使用数据库,最好的方法是使用Web服务为您提供列表 喜欢:This one
答案 3 :(得分:1)
我刚刚从我的数据库中导出了这个列表。
$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"
}
关于城市,我无能为力。