PHP | geoip_continent_code_by_name() Function

The geoip_continent_code_by_name() function is an inbuilt function in PHP which helps to generate a two-letter continent code(Each continent has assigned a two-letter code. For example – AF for Africa, AS for Asia, and many more). The function takes the hostname or IP Address as an argument and generates the two-letter continent code.

Syntax :

string geoip_continent_code_by_name ( string $hostname )
    Parameters : The function geoip_continent_code_by_name() accepts a single parameter as mentioned above and explained below :

  • $hostname : This is the only parameter accepted by the above function . This is the IP address or the hostname which the function accepts and returns the two letter continent code .

Return Values : It returns two letter continent code on success otherwise returns FALSE on failure.

Below programs illustrate the above function :

Program :





// PHP code implementing the
// geoip_continent_code_by_name() function 
// The function accepts the
// hostname as a parameter
$continent = geoip_continent_code_by_name('');
if ($continent) {
       //displays the two letter code
       echo 'This host is located in: '. $continent


Output :

This host is located in: NA

Reference :

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.