<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.vprintf.php',
    1 => 'vprintf',
    2 => 'Output a formatted string',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String Functions',
  ),
  'prev' => 
  array (
    0 => 'function.vfprintf.php',
    1 => 'vfprintf',
  ),
  'next' => 
  array (
    0 => 'function.vsprintf.php',
    1 => 'vsprintf',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/strings/functions/vprintf.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.vprintf" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">vprintf</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.1.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">vprintf</span> &mdash; <span class="dc-title">Output a formatted string</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.vprintf-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>vprintf</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$format</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"><a href="language.types.integer.php" class="type int">int</a></span></div>

  <p class="para rdfs-comment">
   Display array values as a formatted string according to
   <code class="parameter">format</code> (which is described in the documentation
   for <span class="function"><a href="function.sprintf.php" class="function">sprintf()</a></span>).
  </p>
  <p class="para">
   Operates as <span class="function"><a href="function.printf.php" class="function">printf()</a></span> but accepts an array of
   arguments, rather than a variable number of arguments.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.vprintf-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    

 <dt><code class="parameter">format</code></dt>
 <dd>
  <p class="para">
   The format string is composed of zero or more directives:
   ordinary characters (excluding <code class="literal">%</code>) that are
   copied directly to the result and <em>conversion
   specifications</em>, each of which results in fetching its
   own parameter.
  </p>

  <p class="para">
   A conversion specification follows this prototype:
   <code class="literal">%[argnum$][flags][width][.precision]specifier</code>.
  </p>

  <p class="formalpara">
   <h5 class="title">Argnum</h5>
   <p class="para">
    An integer followed by a dollar sign <code class="literal">$</code>,
    to specify which number argument to treat in the conversion.
   </p>
  </p>

  <p class="formalpara">
   <h5 class="title">Flags</h5>
   <p class="para">
    <table class="doctable informaltable">
     
      <thead>
       <tr>
        <th>Flag</th>
        <th>Description</th>
       </tr>

      </thead>

      <tbody class="tbody">
       <tr>
        <td><code class="literal">-</code></td>
        <td>
         Left-justify within the given field width;
         Right justification is the default
        </td>
       </tr>

       <tr>
        <td><code class="literal">+</code></td>
        <td>
         Prefix positive numbers with a plus sign
         <code class="literal">+</code>; Default only negative
         are prefixed with a negative sign.
        </td>
       </tr>

       <tr>
        <td><code class="literal"> </code>(space)</td>
        <td>
         Pads the result with spaces.
         This is the default.
        </td>
       </tr>

       <tr>
        <td><code class="literal">0</code></td>
        <td>
         Only left-pads numbers with zeros.
         With <code class="literal">s</code> specifiers this can
         also right-pad with zeros.
        </td>
       </tr>

       <tr>
        <td><code class="literal">&#039;</code>(char)</td>
        <td>
         Pads the result with the character (char).
        </td>
       </tr>

      </tbody>
     
    </table>

   </p>
  </p>

  <p class="formalpara">
   <h5 class="title">Width</h5>
   <p class="para">
    Either an integer that says how many characters (minimum)
    this conversion should result in, or <code class="literal">*</code>.
    If <code class="literal">*</code> is used, then the width is supplied
    as an additional integer value preceding the one formatted
    by the specifier.
   </p>
  </p>

  <p class="formalpara">
   <h5 class="title">Precision</h5>
   <p class="para">
    A period <code class="literal">.</code> optionally followed by
    either an integer or <code class="literal">*</code>,
    whose meaning depends on the specifier:
    <ul class="itemizedlist">
     <li class="listitem">
      <span class="simpara">
       For <code class="literal">e</code>, <code class="literal">E</code>,
       <code class="literal">f</code> and <code class="literal">F</code>
       specifiers: this is the number of digits to be printed
       after the decimal point (by default, this is 6).
      </span>
     </li>
     <li class="listitem">
      <span class="simpara">
       For <code class="literal">g</code>, <code class="literal">G</code>,
       <code class="literal">h</code> and <code class="literal">H</code>
       specifiers: this is the maximum number of significant
       digits to be printed.
      </span>
     </li>
     <li class="listitem">
      <span class="simpara">
       For <code class="literal">s</code> specifier: it acts as a cutoff point,
       setting a maximum character limit to the string.
      </span>
     </li>
    </ul>
    <blockquote class="note"><p><strong class="note">Note</strong>: 
     <span class="simpara">
      If the period is specified without an explicit value for precision,
      0 is assumed. If <code class="literal">*</code> is used, the precision is
      supplied as an additional integer value preceding the one formatted
      by the specifier.
     </span>
    </p></blockquote>
   </p>
  </p>

  <p class="para">
   <table class="doctable table">
    <caption><strong>Specifiers</strong></caption>
    
     <thead>
      <tr>
       <th>Specifier</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td><code class="literal">%</code></td>
       <td>
        A literal percent character. No argument is required.
       </td>
      </tr>

      <tr>
       <td><code class="literal">b</code></td>
       <td>
        The argument is treated as an integer and presented
        as a binary number.
       </td>
      </tr>

      <tr>
       <td><code class="literal">c</code></td>
       <td>
        The argument is treated as an integer and presented
        as the character with that ASCII.
       </td>
      </tr>

      <tr>
       <td><code class="literal">d</code></td>
       <td>
        The argument is treated as an integer and presented
        as a (signed) decimal number.
       </td>
      </tr>

      <tr>
       <td><code class="literal">e</code></td>
       <td>
        The argument is treated as scientific notation (e.g. 1.2e+2).
       </td>
      </tr>

      <tr>
       <td><code class="literal">E</code></td>
       <td>
        Like the <code class="literal">e</code> specifier but uses
        uppercase letter (e.g. 1.2E+2).
       </td>
      </tr>

      <tr>
       <td><code class="literal">f</code></td>
       <td>
        The argument is treated as a float and presented
        as a floating-point number (locale aware).
       </td>
      </tr>

      <tr>
       <td><code class="literal">F</code></td>
       <td>
        The argument is treated as a float and presented
        as a floating-point number (non-locale aware).
       </td>
      </tr>

      <tr>
       <td><code class="literal">g</code></td>
       <td>
        <p class="para">
         General format.
        </p>
        <p class="para">
         Let P equal the precision if nonzero, 6 if the precision is omitted,
         or 1 if the precision is zero.
         Then, if a conversion with style E would have an exponent of X:
        </p>
        <p class="para">
         If P &gt; X ≥ −4, the conversion is with style f and precision P − (X + 1).
         Otherwise, the conversion is with style e and precision P − 1.
        </p>
       </td>
      </tr>

      <tr>
       <td><code class="literal">G</code></td>
       <td>
        Like the <code class="literal">g</code> specifier but uses
        <code class="literal">E</code> and <code class="literal">f</code>.
       </td>
      </tr>

      <tr>
       <td><code class="literal">h</code></td>
       <td>
        Like the <code class="literal">g</code> specifier but uses <code class="literal">F</code>.
        Available as of PHP 8.0.0.
       </td>
      </tr>

      <tr>
       <td><code class="literal">H</code></td>
       <td>
        Like the <code class="literal">g</code> specifier but uses
        <code class="literal">E</code> and <code class="literal">F</code>. Available as of PHP 8.0.0.
       </td>
      </tr>

      <tr>
       <td><code class="literal">o</code></td>
       <td>
        The argument is treated as an integer and presented
        as an octal number.
       </td>
      </tr>

      <tr>
       <td><code class="literal">s</code></td>
       <td>
        The argument is treated and presented as a string.
       </td>
      </tr>

      <tr>
       <td><code class="literal">u</code></td>
       <td>
        The argument is treated as an integer and presented
        as an unsigned decimal number.
       </td>
      </tr>

      <tr>
       <td><code class="literal">x</code></td>
       <td>
        The argument is treated as an integer and presented
        as a hexadecimal number (with lowercase letters).
       </td>
      </tr>

      <tr>
       <td><code class="literal">X</code></td>
       <td>
        The argument is treated as an integer and presented
        as a hexadecimal number (with uppercase letters).
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>

  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
    The <code class="literal">c</code> type specifier ignores padding and width.
   </p>
  </div>

  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
    Attempting to use a combination of the string and width specifiers with character sets that require more than one byte per character may result in unexpected results.
   </p>
  </div>

  <p class="para">
   Variables will be co-erced to a suitable type for the specifier:
   <table class="doctable table">
    <caption><strong>Type Handling</strong></caption>
    
     <thead>
      <tr>
       <th>Type</th>
       <th>Specifiers</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td><span class="type"><a href="language.types.string.php" class="type string">string</a></span></td>
       <td><code class="literal">s</code></td>
      </tr>

      <tr>
       <td><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></td>
       <td>
        <code class="literal">d</code>,
        <code class="literal">u</code>,
        <code class="literal">c</code>,
        <code class="literal">o</code>,
        <code class="literal">x</code>,
        <code class="literal">X</code>,
        <code class="literal">b</code>
       </td>
      </tr>

      <tr>
       <td><span class="type"><a href="language.types.float.php" class="type float">float</a></span></td>
       <td>
        <code class="literal">e</code>,
        <code class="literal">E</code>,
        <code class="literal">f</code>,
        <code class="literal">F</code>,
        <code class="literal">g</code>,
        <code class="literal">G</code>,
        <code class="literal">h</code>,
        <code class="literal">H</code>
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </dd>


    
     <dt><code class="parameter">values</code></dt>
     <dd>
      <p class="para">
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.vprintf-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the length of the outputted string.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.vprintf-errors">
  <h3 class="title">Errors/Exceptions</h3>
  
  <p class="para">
   As of PHP 8.0.0, a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> is thrown if the number of arguments is zero.
   Prior to PHP 8.0.0, a <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> was emitted instead.
  </p>
  <p class="para">
   As of PHP 8.0.0, a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> is thrown if <code class="literal">[width]</code> is less than zero or bigger than <strong><code><a href="reserved.constants.php#constant.php-int-max">PHP_INT_MAX</a></code></strong>.
   Prior to PHP 8.0.0, a <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> was emitted instead.
  </p>
  <p class="para">
   As of PHP 8.0.0, a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> is thrown if <code class="literal">[precision]</code> is less than zero or bigger than <strong><code><a href="reserved.constants.php#constant.php-int-max">PHP_INT_MAX</a></code></strong>.
   Prior to PHP 8.0.0, a <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> was emitted instead.
  </p>
  <p class="para">
   As of PHP 8.0.0, a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> is thrown when less arguments are given than required.
   Prior to PHP 8.0.0, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> was returned and a <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> emitted instead.
  </p>

 </div>


 <div class="refsect1 changelog" id="refsect1-function.vprintf-changelog">
  <h3 class="title">Changelog</h3>
  
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       This function no longer returns <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       Throw a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> if the number of arguments is zero;
       previously this function emitted a <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> instead.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       Throw a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> if <code class="literal">[width]</code> is less than zero or bigger than <strong><code><a href="reserved.constants.php#constant.php-int-max">PHP_INT_MAX</a></code></strong>;
       previously this function emitted a <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> instead.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       Throw a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> if <code class="literal">[precision]</code> is less than zero or bigger than <strong><code><a href="reserved.constants.php#constant.php-int-max">PHP_INT_MAX</a></code></strong>;
       previously this function emitted a <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> instead.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       Throw a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> when less arguments are given than required;
       previously this function emitted a <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> instead.
      </td>
     </tr>

    </tbody>
   
  </table>


 </div>

 
 <div class="refsect1 examples" id="refsect1-function.vprintf-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>vprintf()</strong></span>: zero-padded integers</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />vprintf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%04d-%02d-%02d"</span><span style="color: #007700">, </span><span style="color: #0000BB">explode</span><span style="color: #007700">(</span><span style="color: #DD0000">'-'</span><span style="color: #007700">, </span><span style="color: #DD0000">'1988-8-1'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">1988-08-01</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.vprintf-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.printf.php" class="function" rel="rdfs-seeAlso">printf()</a> - Output a formatted string</span></li>
    <li><span class="function"><a href="function.sprintf.php" class="function" rel="rdfs-seeAlso">sprintf()</a> - Return a formatted string</span></li>
    <li><span class="function"><a href="function.fprintf.php" class="function" rel="rdfs-seeAlso">fprintf()</a> - Write a formatted string to a stream</span></li>
    <li><span class="function"><a href="function.vsprintf.php" class="function" rel="rdfs-seeAlso">vsprintf()</a> - Return a formatted string</span></li>
    <li><span class="function"><a href="function.vfprintf.php" class="function" rel="rdfs-seeAlso">vfprintf()</a> - Write a formatted string to a stream</span></li>
    <li><span class="function"><a href="function.sscanf.php" class="function" rel="rdfs-seeAlso">sscanf()</a> - Parses input from a string according to a format</span></li>
    <li><span class="function"><a href="function.fscanf.php" class="function" rel="rdfs-seeAlso">fscanf()</a> - Parses input from a file according to a format</span></li>
    <li><span class="function"><a href="function.number-format.php" class="function" rel="rdfs-seeAlso">number_format()</a> - Format a number with grouped thousands</span></li>
    <li><span class="function"><a href="function.date.php" class="function" rel="rdfs-seeAlso">date()</a> - Format a Unix timestamp</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>