<?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 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.vsprintf.php',
    1 => 'vsprintf',
    2 => 'Return a formatted string',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String Функції',
  ),
  'prev' => 
  array (
    0 => 'function.vprintf.php',
    1 => 'vprintf',
  ),
  'next' => 
  array (
    0 => 'function.wordwrap.php',
    1 => 'wordwrap',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/strings/functions/vsprintf.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

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

 </div>
 
 <div class="refsect1 description" id="refsect1-function.vsprintf-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>vsprintf</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.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   Operates as <span class="function"><a href="function.sprintf.php" class="function">sprintf()</a></span> but accepts an array of
   arguments, rather than a variable number of arguments.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.vsprintf-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    

 <dt><code class="parameter">format</code></dt>
 <dd>
  <p class="para">
   Рядок формату складається з нуля або більше директив: звичайних символів
   (крім <code class="literal">%</code>), які відображаються в результаті без змін, та
   <em>специфікаторів перетворення</em>, для кожного з яких
   задається свій параметр.
  </p>

  <p class="para">
   Специфікатор перетворення відповідає прототипу:
   <code class="literal">%[argnum$][flags][width][.precision]specifier</code>.
  </p>

  <p class="formalpara">
   <h5 class="title">Номер параметра</h5>
   <p class="para">
    Ціле число, слідом за ним — знак долара <code class="literal">$</code>. Вказує
    порядковий номер параметра для перетворення.
   </p>
  </p>

  <p class="para">
   <table class="doctable table">
    <caption><strong>Прапорці</strong></caption>
    
     <thead>
      <tr>
       <th>Позначення</th>
       <th>Опис</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td><code class="literal">-</code></td>
       <td>
        Вирівнює по лівому краю в межах заданої ширини. Праве вирівнювання
        виконується автоматично.
       </td>
      </tr>

      <tr>
       <td><code class="literal">+</code></td>
       <td>
        Дописує до додатнього числа знак <code class="literal">+</code>. Знак мінуса до
        від&#039;ємного числа дописується автоматично.
       </td>
      </tr>

      <tr>
       <td><code class="literal"> </code> (пропуск)</td>
       <td>
        Доповнює результат пропусками. Також виконується автоматично.
       </td>
      </tr>

      <tr>
       <td><code class="literal">0</code></td>
       <td>
        Доповнює число нулями ліворуч. Разом зі специфікатором
        <code class="literal">s</code> доповнює число нулями також праворуч.
       </td>
      </tr>

      <tr>
       <td><code class="literal">&#039;</code> (символ)</td>
       <td>
        Доповнює рядок символом (символ).
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>

  <p class="formalpara">
   <h5 class="title">Ширина</h5>
   <p class="para">
    Може бути цілим числом, що вказує найменшу кількість символів в значенні
    після перетворення, або знак <code class="literal">*</code>. Якщо використано
    знак <code class="literal">*</code>, то ширина вказується як додаткове ціле число,
    що передує значенню, відформатованому специфікатором.
   </p>
  </p>

  <p class="formalpara">
   <h5 class="title">Точність</h5>
   <p class="para">
    Крапка <code class="literal">.</code>, за якою (необов&#039;язково) слідує ціле число
    чи знак <code class="literal">*</code>, значення якого залежить від специфікатора:
    <ul class="itemizedlist">
     <li class="listitem">
      <span class="simpara">
       Для специфікаторів <code class="literal">e</code>, <code class="literal">E</code>,
       <code class="literal">f</code> і <code class="literal">F</code> — це кількість знаків, що
       будуть надруковані після десяткового розділювача (початково: 6).
      </span>
     </li>
     <li class="listitem">
      <span class="simpara">
       Для специфікаторів <code class="literal">g</code>, <code class="literal">G</code>,
       <code class="literal">h</code> і <code class="literal">H</code> — найбільша допустима
       кількість значущих цифр, що будуть надруковані.
      </span>
     </li>
     <li class="listitem">
      <span class="simpara">
       Для специфікатора <code class="literal">s</code> — діє як точка відсікання,
       встановлюючи максимальну кількість символів у рядку.
      </span>
     </li>
    </ul>
    <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
     <span class="simpara">
      Якщо крапку вказано без зазначення точності, тоді точністю вважатиметься
      0. Якщо використано знак <code class="literal">*</code>, то точність вказується як
      додаткове ціле число, що передує значенню, відформатованому специфікатором.
     </span>
    </p></blockquote>
   </p>
  </p>

  <p class="para">
   <table class="doctable table">
    <caption><strong>Специфікатори</strong></caption>
    
     <thead>
      <tr>
       <th>Назва</th>
       <th>Опис</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td><code class="literal">%</code></td>
       <td>
        Буквальний знак відсотка. Ніяких параметрів не потрібно.
       </td>
      </tr>

      <tr>
       <td><code class="literal">b</code></td>
       <td>
        Параметр розглядається як ціле число і відображається як двійкове число.
       </td>
      </tr>

      <tr>
       <td><code class="literal">c</code></td>
       <td>
        Параметр розглядається як ціле число і відображається як символ з таким
        кодом ASCII.
       </td>
      </tr>

      <tr>
       <td><code class="literal">d</code></td>
       <td>
        Параметр розглядається як ціле число і відображається як знакове
        десяткове число.
       </td>
      </tr>

      <tr>
       <td><code class="literal">e</code></td>
       <td>
        Параметр розглядається як експоненційний запис (напр. 1.2e+2).
       </td>
      </tr>

      <tr>
       <td><code class="literal">E</code></td>
       <td>
        Схожий до специфікатора <code class="literal">e</code>, але використовує знак
        експоненти з великої букви (напр. 1.2E+2).
       </td>
      </tr>

      <tr>
       <td><code class="literal">f</code></td>
       <td>
        Параметр розглядається і відображається як десятковий дріб (з
        урахуванням локалі).
       </td>
      </tr>

      <tr>
       <td><code class="literal">F</code></td>
       <td>
        Параметр розглядається і відображається як десятковий дріб (БЕЗ
        урахування локалі).
       </td>
      </tr>

      <tr>
       <td><code class="literal">g</code></td>
       <td>
        <p class="para">
         Загальний формат.
        </p>
        <p class="para">
         Нехай <code class="literal">P</code> дорівнює точності, якщо вона не дорівнює
         нулю, 6, якщо точність не вказано, або 1, якщо точність дорівнює нулю.
         Тоді, якщо перетворення в стилі &quot;E&quot; матиме показник степеня
         <code class="literal">X</code>:
        </p>
        <p class="para">
         Якщо P &gt; X ≥ −4, перетворення буде в стилі &quot;f&quot; та з точністю P − (X +
         1). Інакше, перетворення буде в стилі &quot;e&quot; та з точністю P − 1.
        </p>
       </td>
      </tr>

      <tr>
       <td><code class="literal">G</code></td>
       <td>
        Схожий до специфікатора <code class="literal">g</code>, але використовує
        <code class="literal">E</code> та <code class="literal">f</code>.
       </td>
      </tr>

      <tr>
       <td><code class="literal">h</code></td>
       <td>
        Схожий до специфікатора <code class="literal">g</code>, але використовує
        <code class="literal">F</code>. Доступний, починаючи з PHP 8.0.0.
       </td>
      </tr>

      <tr>
       <td><code class="literal">H</code></td>
       <td>
        Схожий до специфікатора <code class="literal">g</code>, але використовує
        <code class="literal">E</code> та <code class="literal">F</code>. Доступний, починаючи з
        PHP 8.0.0.
       </td>
      </tr>

      <tr>
       <td><code class="literal">o</code></td>
       <td>
        Параметр розглядається як ціле число і відображається як вісімкове число.
       </td>
      </tr>

      <tr>
       <td><code class="literal">s</code></td>
       <td>
        Параметр розглядається і відображається як рядок.
       </td>
      </tr>

      <tr>
       <td><code class="literal">u</code></td>
       <td>
        Параметр розглядається як ціле число і відображається як беззнакове
        десяткове число.
       </td>
      </tr>

      <tr>
       <td><code class="literal">x</code></td>
       <td>
        Параметр розглядається як ціле число і відображається як шіснадцяткове
        число (з малими буквами).
       </td>
      </tr>

      <tr>
       <td><code class="literal">X</code></td>
       <td>
        Параметр розглядається як ціле число і відображається як шіснадцяткове
        число (з великими буквами).
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>

  <div class="warning"><strong class="warning">Увага</strong>
   <p class="para">
    Специфікатор <code class="literal">&quot;c&quot;</code> ігнорує заповнення та ширину.
   </p>
  </div>

  <div class="warning"><strong class="warning">Увага</strong>
   <p class="para">
    Спроба використати разом рядковий специфікатор та специфікатор ширини з
    символами, що займають більше одного байта, може призвести до неочікуваного
    результату.
   </p>
  </div>

  <p class="para">
   Змінні будуть приведені до відповідного типу для специфікатора:
   <table class="doctable table">
    <caption><strong>Обробка типів</strong></caption>
    
     <thead>
      <tr>
       <th>Тип</th>
       <th>Специфікатор</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.vsprintf-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Return array values as a formatted string according to
   <code class="parameter">format</code>.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.vsprintf-errors">
  <h3 class="title">Помилки/виключення</h3>
  
  <p class="para">
   Починаючи з PHP 8.0.0, якщо не задано жодного параметра, то викидається
   <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span>. Раніше виводилось повідомлення
   <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>.
  </p>
  <p class="para">
   Починаючи з PHP 8.0.0, якщо значення <code class="literal">[width]</code> менше за нуль
   або більше за <strong><code><a href="reserved.constants.php#constant.php-int-max">PHP_INT_MAX</a></code></strong>, то викидається
   <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span>. Раніше виводилось повідомлення
   <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>.
  </p>
  <p class="para">
   Починаючи з PHP 8.0.0, якщо значення <code class="literal">[precision]</code> менше за
   нуль або більше за <strong><code><a href="reserved.constants.php#constant.php-int-max">PHP_INT_MAX</a></code></strong>, то викидається
   <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span>. Раніше виводилось повідомлення
   <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>.
  </p>
  <p class="para">
   Починаючи з PHP 8.0.0, якщо якщо не задано обов&#039;язкові параметри, то
   викидається <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span>. Раніше функція повертала
   <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, а також виводилося повідомлення <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>.
  </p>

 </div>


 <div class="refsect1 changelog" id="refsect1-function.vsprintf-changelog">
  <h3 class="title">Журнал змін</h3>
  
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Версія</th>
      <th>Опис</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       Ця функція більше не повертає <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> у разі помилки.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       Викидає <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span>, якщо не задано жодного
       параметра. Раніше ця функція виводила <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       Викидає <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span>, якщо значення
       <code class="literal">[width]</code> менше за нуль або більше за
       <strong><code><a href="reserved.constants.php#constant.php-int-max">PHP_INT_MAX</a></code></strong>. Раніше ця функція виводила
       <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       Викидає <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span>, якщо значення
       <code class="literal">[precision]</code> менше за нуль або більше за
       <strong><code><a href="reserved.constants.php#constant.php-int-max">PHP_INT_MAX</a></code></strong>. Раніше ця функція виводила
       <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       Викидає <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span>, якщо не задано
       обов&#039;язкові параметри. Раніше ця функція виводила
       <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>.
      </td>
     </tr>

    </tbody>
   
  </table>


 </div>


 <div class="refsect1 examples" id="refsect1-function.vsprintf-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 <span class="function"><strong>vsprintf()</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 /></span><span style="color: #007700">print </span><span style="color: #0000BB">vsprintf</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>Поданий вище приклад
виведе:</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.vsprintf-seealso">
  <h3 class="title">Прогляньте також</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.vprintf.php" class="function" rel="rdfs-seeAlso">vprintf()</a> - Output 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); ?>