Skip to content
Tutorials Center
My learning

Topics

PHP Reference Β· Standard PHP Library and Classes

The intl extension and its classes

Overview of the PHP intl extension: NumberFormatter, IntlDateFormatter, Collator, Locale, MessageFormatter and Normalizer for locale-aware formatting, sorting and text handling.

The intl extension connects PHP to the ICU library, the same internationalization data used by many browsers and operating systems. It knows how each locale writes numbers, currencies, dates and plurals, how it sorts words and how its text is normalized. Doing this by hand with number_format() and date() only covers one convention at a time.

The extension is optional: it must be installed and enabled (extension_loaded('intl')). The runner on this site does not include it, so the intl examples here are read-only; the live examples show how to detect the extension and what to do without it.

PHP
$fmt = new NumberFormatter('de_DE', NumberFormatter::DECIMAL);
echo $fmt->format(1234567.891);   // 1.234.567,891

Try it

PHP Detect intl and fall back gracefully

Press Run (or Ctrl + Enter) to see the result here.

Program input Β· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

PHP Sorting words without Collator

Press Run (or Ctrl + Enter) to see the result here.

Program input Β· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

Main classes and functions

Class or function Purpose
NumberFormatter Locale-aware numbers, currencies, percentages, spelled-out numbers and ordinals.
IntlDateFormatter Formats and parses dates and times for a locale and time zone, using styles or ICU patterns.
Collator Language-aware string comparison and sorting (sort(), compare(), asort()).
Locale Parses and builds locale identifiers (en_US, de-CH), finds the best match for an Accept-Language header.
MessageFormatter Messages with named placeholders and plural/select rules.
Normalizer Unicode normalization forms (NFC, NFD, NFKC, NFKD).
Transliterator Converts between scripts, or strips accents (for slugs).
IntlChar, grapheme_*() Character properties and user-perceived character (grapheme) handling.
idn_to_ascii(), idn_to_utf8() Internationalized domain names (punycode).

Read-only examples

PHP
$date = new DateTimeImmutable('2026-01-05 14:30:00', new DateTimeZone('UTC'));

$fmt = new IntlDateFormatter('en_US', IntlDateFormatter::NONE, IntlDateFormatter::NONE,
    'UTC', null, 'EEEE, d MMMM yyyy');
echo $fmt->format($date);         // Monday, 5 January 2026

$de = new IntlDateFormatter('de_DE', IntlDateFormatter::NONE, IntlDateFormatter::NONE,
    'UTC', null, 'EEEE, d. MMMM yyyy');
echo $de->format($date);          // Montag, 5. Januar 2026

$collator = new Collator('sv_SE');
$names = ['Zorro', 'Γ…ke', 'Anna'];
$collator->sort($names);          // Anna, Zorro, Γ…ke (Swedish puts Γ… after Z)

echo Transliterator::create('Any-Latin; Latin-ASCII')->transliterate('Ε koda Γ…re');
// Skoda Are

echo Normalizer::normalize("e\u{0301}", Normalizer::FORM_C) === "\u{00E9}" ? "equal" : "different";

Usage notes

  • Install it first. On Linux it is the php-intl package; on Windows enable extension=intl. Check with php -m or extension_loaded('intl').
  • Output depends on the ICU version. Spaces in formatted output may be non-breaking or narrow non-breaking spaces (French groups, "€" after the number in German). Do not compare strings against hard-coded literals across servers.
  • Use Collator, not strcmp(), to sort user-visible names. Plain sorting orders by bytes, so uppercase letters come first and accented letters last.
  • strftime() is deprecated since PHP 8.1 and has no locale support worth relying on. Use IntlDateFormatter or DateTimeInterface::format() plus translation tables.
  • Errors are quiet by default. Most intl methods return false or null on failure; check intl_get_error_message() or the object's getErrorMessage().
  • Patterns differ from date(). ICU uses yyyy-MM-dd HH:mm, not Y-m-d H:i, and MM means month while mm means minutes.
  • Pair with mbstring, which handles encodings and case but not locale rules.