$user_ip = getenv('REMOTE_ADDR');

$geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$user_ip"));

$city = $geo["geoplugin_city"];

$region = $geo["geoplugin_regionName"];

$country = $geo["geoplugin_countryName"];

$continent = $geo["geoplugin_continentCode"];

$continent1 = $continent;

echo "IP: " .$user_ip. "<br>";

echo "City: " .$city. "<br>";

echo "Region: " .$region. "<br>";

echo "Country: " .$country. "<br>";

echo "Continent: " .$continent1. "<br>";

此代码用于获取IP和位置详细信息。
在这里,我的问题是,我得到的大陆是as,EU,NA,SA
我需要改变亚洲,欧盟到欧洲,北美到北美,南美到南美。如何对此使用if else条件?

最佳答案

试试这个-

switch ($continent1) {
    case "AS":
        $continent1 = 'Asia';
        break;
    case "EU":
        $continent1 = 'Europe';
        break;
    case "NA":
        $continent1 = 'North America';
        break;
    default:
        $continent1 = '';
}

09-16 10:55