https://github.com/writecrow/country_code_converter
A simple converter to/from country names & 2- or 3-digit codes
https://github.com/writecrow/country_code_converter
php-library
Last synced: about 2 months ago
JSON representation
A simple converter to/from country names & 2- or 3-digit codes
- Host: GitHub
- URL: https://github.com/writecrow/country_code_converter
- Owner: writecrow
- License: mit
- Created: 2017-08-10T23:40:55.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2024-01-04T14:27:40.000Z (over 1 year ago)
- Last Synced: 2025-03-26T20:51:24.140Z (2 months ago)
- Topics: php-library
- Language: PHP
- Size: 20.5 KB
- Stars: 5
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Country Code Converter
[](https://circleci.com/gh/writecrow/country_code_converter)
A PHP library for converting ISO country codes to names and vice-versa.
Country data was last updated on August 10, 2017, from
[https://en.wikipedia.org/wiki/ISO_3166-1#Officially_assigned_code_elements](https://en.wikipedia.org/wiki/ISO_3166-1#Officially_assigned_code_elements)The library recognizes ISO 2-digit, 3-digit, and numeric codes.
## Usage in an application
The included `/demo/index.php` file contains a generation form demo.Make your code aware of the CountryCodeConverter class via your favorite method
(e.g., `use` or `require`)Then pass a country code or country name into the class:
```php
echo CountryCodeConverter::convert('AL');
// Will print 'Albania'echo CountryCodeConverter::convert('ALB');
// Will print 'Albania'echo CountryCodeConverter::convert('008');
// Will print 'Albania'echo CountryCodeConverter::convert('Albania');
// Will print 'AL'
```### Explicitly requesting return format.
If you want a specific format returned, pass the desired format as a second
parameter:```php
echo CountryCodeConverter::convert('Albania', 'name');
// Will print 'Albania'echo CountryCodeConverter::convert('Albania', 'two-digit');
// Will print 'AL'echo CountryCodeConverter::convert('Albania', 'three-digit');
// Will print 'ALB'echo CountryCodeConverter::convert('Albania', 'numeric');
// Will print '008'
```