downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

MessageFormatter::formatMessage> <MessageFormatter
[edit] Last updated: Fri, 17 May 2013

view this page in

MessageFormatter::create

MessageFormatter::__construct

msgfmt_create

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

MessageFormatter::create -- MessageFormatter::__construct -- msgfmt_createConstruit un nouveau formateur de messages

Description

Style orienté objet (méthode)

MessageFormatter MessageFormatter::create ( string $locale , string $pattern )

Style orienté objet (constructeur)

MessageFormatter::__construct() ( string $locale , string $pattern )

Style procédural

MessageFormatter msgfmt_create ( string $locale , string $pattern )

Construit un nouveau formateur de messages.

Liste de paramètres

locale

La locale à utiliser pour le formatage des arguments

pattern

La chaîne dans laquelle il faut insérer les données. Le modèle utilise une syntaxe qui accepte les apostrophes. Elle est passée à » umsg_autoQuoteApostrophe avant d'être interprétée.

Valeurs de retour

Un objet de formateur de message MessageFormatter

Exemples

Exemple #1 Exemple avec msgfmt_create(), style procédural

<?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(45601234560/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(45601234560/123));
?>

Exemple #2 Exemple avec msgfmt_create(), style procédural

<?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(45601234560/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(45601234560/123));
?>

L'exemple ci-dessus va afficher :

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

Voir aussi



add a note add a note User Contributed Notes MessageFormatter::create - [1 notes]
up
0
ezarko at synacor dot com
3 years ago
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',''));"

 
show source | credits | stats | sitemap | contact | advertising | mirror sites