(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
MessageFormatter::create -- MessageFormatter::__construct -- msgfmt_create — Constructs a new Message Formatter
面向对象风格 (method)
面向对象风格 (constructor):
过程化风格
Constructs a new Message Formatter
The locale to use when formatting arguments
The pattern string to stick arguments into. The pattern uses an 'apostrophe-friendly' syntax; it is run through » umsg_autoQuoteApostrophe before being interpreted.
The formatter object
When invoked as constructor, on failure an IntlException is thrown.
示例 #1 msgfmt_create() example
示例 #2 OO example
以上例程会输出:
4,560 monkeys on 123 trees make 37.073 monkeys per tree 4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum
[#1] ▲3▼ ezarko@synacor.com [100%] (2009-10-05 15:18:52)
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',''));"