PHP Conference Fukuoka 2025

Uso básico de esta extensión

Cada módulo proporciona dos tipos de APIs: una procedimental y otra orientada a objetos. En realidad, ambas son idénticas y están descritas en su correspondiente documentación.

Nota:

Todos los strings de entrada deben estar codificados en UTF-8. Del mismo modo, todos los strings de salida deberán estar también en UTF-8.

Ejemplo #1 Ejemplo usando la API procedimental

<?php
$cotejamiento
= collator_create('en_US');
$resultado = collator_compare($cotejamiento, "string#1", "string#2");
?>

Ejemplo #2 Ejemplo usando la API orientada a objetos

<?php
$cotejamiento
= new Collator('en_US');
$al = $cotejamiento->getLocale(Locale::ACTUAL_LOCALE);
echo
"Configuración regional real: $al\n";

$formateador = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
echo
$formateador->format(1234567);
?>
add a note

User Contributed Notes 2 notes

up
2
RoboTamer
13 years ago
Get the default currency for a country:

<?php
$formatter = new NumberFormatter('de_DE', NumberFormatter::CURRENCY);
echo $formatter->getTextAttribute(NumberFormatter::CURRENCY_CODE);

$formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY);
echo $formatter->getTextAttribute(NumberFormatter::CURRENCY_CODE);

$formatter = new NumberFormatter('ja_JP', NumberFormatter::CURRENCY);
echo $formatter->getTextAttribute(NumberFormatter::CURRENCY_CODE);
?>
up
0
Anonymous
17 days ago
Using the getLocale() prints out my current username.<?php$coll = new Collator('en_US');$al   = $coll->getLocale(Locale::ACTUAL_LOCALE);echo "Actual locale: $al\n";?>Actual locale: root
To Top