Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting country and city

Tags:

html

php

select

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.

like image 239
good_evening Avatar asked Nov 21 '25 16:11

good_evening


1 Answers

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.

like image 119
Alix Axel Avatar answered Nov 24 '25 04:11

Alix Axel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!