How can I ensure consistency in displaying country names from WhoIs results in PHP applications?

When displaying country names from WhoIs results in PHP applications, it's important to ensure consistency in the formatting of the country names. One way to achieve this is by using a mapping array that maps the country codes returned by WhoIs to their corresponding country names. By referencing this mapping array when displaying the country names, you can ensure that they are consistently formatted across your application.

// Mapping array to map country codes to country names
$countryMapping = array(
    'US' => 'United States',
    'CA' => 'Canada',
    'GB' => 'United Kingdom',
    // Add more country code mappings as needed
);

// Sample WhoIs result with country code
$countryCode = 'US';

// Displaying the country name using the mapping array
if (isset($countryMapping[$countryCode])) {
    echo 'Country: ' . $countryMapping[$countryCode];
} else {
    echo 'Country: Unknown';
}