<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/book.intl.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'class.messageformatter.php',
    1 => 'MessageFormatter',
    2 => 'The MessageFormatter class',
  ),
  'up' => 
  array (
    0 => 'book.intl.php',
    1 => 'intl',
  ),
  'prev' => 
  array (
    0 => 'normalizer.normalize.php',
    1 => 'Normalizer::normalize',
  ),
  'next' => 
  array (
    0 => 'messageformatter.create.php',
    1 => 'MessageFormatter::create',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/intl/messageformatter.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/class.messageformatter.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="class.messageformatter" class="reference">
 <h1 class="title">The MessageFormatter class</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL intl &gt;= 1.0.0)</p>

  
  <div class="section" id="messageformatter.intro">
   <h2 class="title">Introduction</h2>
   <p class="simpara">
    MessageFormatter is a concrete class that enables users to produce
    concatenated, language-neutral messages. The methods supplied in this
    class are used to build all the messages that are seen by end users.
   </p>
   <p class="simpara">
    The MessageFormatter class assembles messages from various fragments (such
    as text fragments, numbers, and dates) supplied by the program. Because of
    the MessageFormatter class, the program does not need to know the order of
    the fragments. The class uses the formatting specifications for the
    fragments to assemble them into a message that is contained in a single
    string within a resource bundle. For example, MessageFormatter enables you
    to print the phrase &quot;Finished printing x out of y files...&quot; in a manner
    that still allows for flexibility in translation.
   </p>
   <p class="simpara">
    Previously, an end user message was created as a sentence and handled as a
    string. This procedure created problems for localizers because the
    sentence structure, word order, number format and so on are very different
    from language to language. The language-neutral way to create messages
    keeps each part of the message separate and provides keys to the data.
    Using these keys, the MessageFormatter class can concatenate the parts of
    the message, localize them, and display a well-formed string to the end
    user.
   </p>
   <p class="simpara">
    MessageFormatter takes a set of objects, formats them, and then inserts
    the formatted strings into the pattern at the appropriate places. Choice
    formats can be used in conjunction with MessageFormatter to handle
    plurals, match numbers, and select from an array of items. Typically, the
    message format will come from resources and the arguments will be
    dynamically set at runtime.
   </p>
  </div>
  

  <div class="section" id="messageformatter.synopsis">
   <h2 class="title">Class synopsis</h2>

   
   <div class="classsynopsis"><div class="classsynopsisinfo">
    
     <span class="modifier">class</span> <strong class="classname"><strong class="classname">MessageFormatter</strong></strong>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Methods */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="messageformatter.create.php" class="methodname">__construct</a></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$locale</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$pattern</code></span>)</div>

    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="messageformatter.create.php" class="methodname">create</a></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$locale</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$pattern</code></span>): <span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="class.messageformatter.php" class="type MessageFormatter">MessageFormatter</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="messageformatter.format.php" class="methodname">format</a></span>(<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$values</code></span>): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="messageformatter.formatmessage.php" class="methodname">formatMessage</a></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$locale</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$pattern</code></span>, <span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$values</code></span>): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="messageformatter.geterrorcode.php" class="methodname">getErrorCode</a></span>(): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="messageformatter.geterrormessage.php" class="methodname">getErrorMessage</a></span>(): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="messageformatter.getlocale.php" class="methodname">getLocale</a></span>(): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="messageformatter.getpattern.php" class="methodname">getPattern</a></span>(): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="messageformatter.parse.php" class="methodname">parse</a></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string</code></span>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="messageformatter.parsemessage.php" class="methodname">parseMessage</a></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$locale</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$pattern</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$message</code></span>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="messageformatter.setpattern.php" class="methodname">setPattern</a></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$pattern</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

   }</div>
   

  </div>

  <div class="section" id="messageformatter.seealso">
   <h2 class="title">See Also</h2>
   <p class="para">
    <ul class="simplelist">
     <li>
      <a href="https://unicode-org.github.io/icu/userguide/format_parse/" class="link external">&raquo;&nbsp;
       ICU formatting documentation
      </a>
     </li>
     <li>
      <a href="https://unicode-org.github.io/icu/userguide/format_parse/messages/" class="link external">&raquo;&nbsp;
       ICU message formatting description
      </a>
     </li>
     <li>
      <a href="https://unicode-org.github.io/icu/userguide/format_parse/messages/" class="link external">&raquo;&nbsp;ICU message formatters</a>
     </li>
     <li>
      <a href="https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classChoiceFormat.html" class="link external">&raquo;&nbsp;ICU choice formatters</a>
     </li>
    </ul>
   </p>
  </div>
 </div>

 


















































<h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="messageformatter.create.php">MessageFormatter::create</a> — Constructs a new Message Formatter</li><li><a href="messageformatter.format.php">MessageFormatter::format</a> — Format the message</li><li><a href="messageformatter.formatmessage.php">MessageFormatter::formatMessage</a> — Quick format message</li><li><a href="messageformatter.geterrorcode.php">MessageFormatter::getErrorCode</a> — Get the error code from last operation</li><li><a href="messageformatter.geterrormessage.php">MessageFormatter::getErrorMessage</a> — Get the error text from the last operation</li><li><a href="messageformatter.getlocale.php">MessageFormatter::getLocale</a> — Get the locale for which the formatter was created</li><li><a href="messageformatter.getpattern.php">MessageFormatter::getPattern</a> — Get the pattern used by the formatter</li><li><a href="messageformatter.parse.php">MessageFormatter::parse</a> — Parse input string according to pattern</li><li><a href="messageformatter.parsemessage.php">MessageFormatter::parseMessage</a> — Quick parse input string</li><li><a href="messageformatter.setpattern.php">MessageFormatter::setPattern</a> — Set the pattern used by the formatter</li></ul>
</div>
<?php manual_footer($setup); ?>