IsoFlags
A modern PHP library for generating emoji flags from ISO 3166-1 alpha-2 country codes and extended regional codes.
Features
Generate emoji flags from ISO 3166-1 alpha-2 country codes Extended regional codes support (Kosovo, Ascension Island, etc.) Type-safe with PHP 8.4 enums Static and instance methods available 100% test coverage (257 tests, 1018 assertions) Zero dependencies - only requires PHP 8.4+
Quick Example
use Rteeom\FlagsGenerator\FlagsGenerator;
// Get flag emoji
echo FlagsGenerator::getFlag('gb'); // π¬π§
echo FlagsGenerator::getFlag('ua'); // πΊπ¦
echo FlagsGenerator::getFlag('us'); // πΊπΈ
// Safely get flag or null
$flag = FlagsGenerator::getFlagOrNull('invalid'); // null
Installation
Install via Composer:
Requirements: PHP 8.4 or higher
How It Works
The library converts two-letter country codes to emoji flags by transforming each letter into its corresponding Regional Indicator Symbol:
- Each letter is converted to its Unicode codepoint (offset by 127365)
- The codepoint is encoded to UTF-8 bytes using native PHP functions
- Regional Indicator Symbols (U+1F1E6 to U+1F1FF) combine to form flag emojis
Example: GB becomes:
Gβ π¬ (U+1F1EC = 127468)Bβ π§ (U+1F1E7 = 127463)- Combined: π¬π§
The library uses no external dependencies - just native PHP byte packing to generate UTF-8 encoded emoji flags.
What's Next?
- Installation Guide - Detailed installation instructions
- Quick Start - Get started in 2 minutes
- Basic Usage - Learn the core functionality
- Extended Codes - Kosovo, Ascension Island, and more
- API Reference - Complete API documentation
Support
- GitHub Issues: Report bugs or request features
- Packagist: View on Packagist
- Email: mainstreamer@outlook.com
License
MIT License - see LICENSE file for details.