i want to input the country code like "fr" and get the largest city "paris" , and if possible also the continent, in PHP !
Asked
Active
Viewed 123 times
-5
-
you want code for this? We're not here to do your job for you. Write your own code. You need pointers to an API that can do such geo-type queries? We're not a search engine. – Marc B Jul 04 '13 at 17:07
-
1The [geoip extension](http://www.php.net/manual/en/book.geoip.php) might help you, or look into the Google maps APIs... – nice ass Jul 04 '13 at 17:07
-
1U need to specify the data source IMHO – DaGhostman Dimitrov Jul 04 '13 at 17:08
-
I love to see such questions. Even more when those are answered. Nice. – devnull Jul 04 '13 at 17:17
-
@Miguelo : i didn't try anything, i'm working around Carbon https://github.com/briannesbitt/Carbon ! – EvilThinker Jul 04 '13 at 17:19
-
then first try something and comeback when you run into problems – Miguelo Jul 04 '13 at 17:20
-
@Marc : i'm not asking you to do my job, i'm looking for an API , Library or some open source database that i can use! – EvilThinker Jul 04 '13 at 17:22
-
@One Trick : thank you , the extension is helpful ! – EvilThinker Jul 04 '13 at 17:26
-
1@EvilThinker: Asking others for off-site resources like libraries, APIs or databases is off-topic. But thanks for the clarification. – hakre Jul 04 '13 at 22:44
1 Answers
0
Extend to your needs, I already added the city you asked for:
$largest = [
'fr' => 'paris',
];
$code = 'fr';
echo $largest[$code];
You can further improve this by wrapping it into a class supporting ArrayAccess
giving a default value in case it does not exist.

hakre
- 193,403
- 52
- 435
- 836
-
-
thanks but what i'm looking for exactly is a database with largest cities ! – EvilThinker Jul 04 '13 at 17:25
-
@EvilThinker: And you weren't able to google for those? Poor boy, try harder I'd say. Why don't you just take http://en.wikipedia.org/wiki/List_of_largest_cities_and_second_largest_cities_by_country ? – hakre Jul 04 '13 at 22:36
-
@hakre because it's working trust me , but i got a solution i will post it ! – EvilThinker Jul 04 '13 at 23:00
-
i needed to the get the largest city of a particular country to use in a timezone identifier in Carbon library , but i got a pretty useful function print_r(DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $country_code)); – EvilThinker Jul 04 '13 at 23:14