Beware: passing an empty string for format returns null, not a formatter which returns empty strings.
$ php -r "print_r(new MessageFormatter('en_US',' '));"
MessageFormatter Object
(
)
$ php -r "print_r(new MessageFormatter('en_US',''));"
(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)
MessageFormatter::create -- MessageFormatter::__construct -- msgfmt_create — Construye un nuevo formateador de mensajes
Estilo orientado a objetos (método)
Estilo orientado a objetos (constructor)
Estilo procedimental
Construye un nuevo formateador de mensajes.
locale
La configuración local a utilizar para el formato de los argumentos
pattern
La cadena en la que se deben insertar los datos. El modelo utiliza una sintaxis que acepta comillas simples. Ver » Quoting/Escaping para más detalles.
Un objeto de formateador de mensajes MessageFormatter, o null
en caso de fallo.
Cuando se invoca como constructor, IntlException es lanzado en caso de fallo.
Ejemplo #1 Ejemplo con msgfmt_create(), estilo procedimental
<?php
$fmt = msgfmt_create("en_US", "{0,number,integer} singes sur {1,number,integer} arbres font {2,number} singes par arbre");
echo msgfmt_format($fmt, array(4560, 123, 4560/123));
$fmt = msgfmt_create("de", "{0,number,integer} Affen über {1,number,integer} Bäume um {2,number} Affen pro Baum");
echo msgfmt_format($fmt, array(4560, 123, 4560/123));
?>
Ejemplo #2 Ejemplo con msgfmt_create(), estilo procedimental
<?php
$fmt = new MessageFormatter("en_US", "{0,number,integer} singes sur {1,number,integer} arbres font {2,number} singes par arbre");
echo $fmt->format(array(4560, 123, 4560/123));
$fmt = new MessageFormatter("de", "{0,number,integer} Affen über {1,number,integer} Bäume um {2,number} Affen pro Baum");
echo $fmt->format(array(4560, 123, 4560/123));
?>
El ejemplo anterior mostrará :
4,560 singes sur 123 arbres font 37.073 singes par arbre 4.560 Affen über 123 Bäume um 37,073 Affen pro Baum
Beware: passing an empty string for format returns null, not a formatter which returns empty strings.
$ php -r "print_r(new MessageFormatter('en_US',' '));"
MessageFormatter Object
(
)
$ php -r "print_r(new MessageFormatter('en_US',''));"