Locale::canonicalize

locale_canonicalize

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

Locale::canonicalize -- locale_canonicalizeCanonicalize the locale string

Descrizione

public static Locale::canonicalize(string $locale): ?string

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).

Elenco dei parametri

locale
Original locale string.

Valori restituiti

Canonicalized locale string.

Returns null when the length of locale exceeds INTL_MAX_LOCALE_LEN.

Esempi

Example #1 locale_canonicalize() example

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

Il precedente esempio visualizzerà qualcosa simile a:

en_US
totally_NOT_VALID
add a note

User Contributed Notes 1 note

up
3
jerome at chaman dot ca
9 years ago
this method performs Level 1 and Level 2 canonicalization according to ICU standards. See http://userguide.icu-project.org/locale#TOC-Canonicalization. echo \Locale::canonicalize ( 'en-US.utf8' ); // "en_U"echo \Locale::canonicalize ( 'FR-fr@EURO' ); // "fr_FR@currency=EUR"echo \Locale::canonicalize ( '' ); // "en_US_POSIX"
To Top