PHP 8.5.0 Alpha 2 available for testing

MessageFormatter::format

msgfmt_format

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

MessageFormatter::format -- msgfmt_formatFormatea un mensaje

Descripción

Estilo orientado a objetos

public MessageFormatter::format(array $values): string|false

Estilo procedimental

msgfmt_format(MessageFormatter $formatter, array $values): string|false

Formatea un mensaje sustituyendo los datos en las cadenas de modelo, según las convenciones locales.

Parámetros

formatter

Un objeto de formateador de mensajes MessageFormatter

values

Los argumentos a insertar en las cadenas

Valores devueltos

La cadena formateada, false si ocurre un error.

Ejemplos

Ejemplo #1 Ejemplo con msgfmt_format(), 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_format(), estilo POO

<?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

Ver también

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top