php8.5
Home/ Manual/ intl / locale/ Locale::canonicalize

Locale::canonicalize

PHP function Edit on GitHub ✎

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)

Canonicalize the locale string

Description

Locale::canonicalize(string $locale): string|null

Canonicalizes the passed locale string to ICU format.

This does not necessarily indicate or return a valid locale. It is only a version of the input that has been canonicalized according to ICU rules.

The behavior of this function depends on the version of ICU PHP is using (INTL_ICU_VERSION).

Parameters

locale

Original locale string.

Return Values

Canonicalized locale string.

Return

Examples

locale_canonicalize() example

php
echo Locale::canonicalize('en-US.utf8') . "\n";
echo Locale::canonicalize('totally-not-valid') . "\n";

The above example will output something similar to:

output
en_US
totally_NOT_VALID

Source: reference/intl/locale/canonicalize.xml · from the official PHP manual (php/doc-en)