Intermediate LevelPHP 8+
How do you implement currency formatting and date localization using the PHP Intl extension?
❓ Interview Prompt: Explain PHP Intl extension (ICU wrapper), NumberFormatter, DateTimeFormatter, currency formatting, and locale rules.
The PHP Intl extension is a wrapper for the C ICU (International Components for Unicode) library, providing locale-aware number, currency, date, and message formatting.
Key Classes:
•
'NumberFormatter': Formats numbers and currencies according to regional cultural standards (e.g. '1.234,56 €' in Germany vs '$1,234.56' in US).
•
'IntlDateFormatter': Formats dates and times in local language scripts.
Code Implementation Example
php
<?php
// 1. Currency Formatting for Germany (de_DE)
$fmtDE = new NumberFormatter('de_DE', NumberFormatter::CURRENCY);
echo $fmtDE->formatCurrency(1234.56, 'EUR'); // Outputs: 1.234,56 €
// 2. Currency Formatting for US (en_US)
$fmtUS = new NumberFormatter('en_US', NumberFormatter::CURRENCY);
echo $fmtUS->formatCurrency(1234.56, 'USD'); // Outputs: $1,234.56💡Formatting localized currency using PHP Intl NumberFormatter extension.
🎯 Interview Key Takeaway
Use the PHP Intl extension (NumberFormatter) for culturally accurate currency and date localization.
#Intl#Localization#Currency#Intermediate
Back to all PHP 8+ Questions→