PHP intl country code 2 chars to country name

后端 未结 8 1045
猫巷女王i
猫巷女王i 2021-02-18 17:57

I\'m triying to convert, using PHP, 2 characters country code (ISO 3166-1) to country names, or intl country codes, so I can translate the country name.

Using Loca

8条回答
  •  执笔经年
    2021-02-18 18:28

    You can get a JSON mapping of ISO2 country code to name at http://country.io/names.json. Here's a simple PHP example that makes use of it:

    $names = json_decode(file_get_contents("http://country.io/names.json"), true);
    echo $names['US'];
    // => United States
    echo $names['NL'];
    // => Netherlands
    

    See http://country.io/data/ for more related data.

提交回复
热议问题