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.
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.
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.
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
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.
精彩评论