<?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.str-pad.php',
    1 => 'str_pad',
    2 => 'Pad a string to a certain length with another string',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String Functions',
  ),
  'prev' => 
  array (
    0 => 'function.str-ireplace.php',
    1 => 'str_ireplace',
  ),
  'next' => 
  array (
    0 => 'function.str-repeat.php',
    1 => 'str_repeat',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/strings/functions/str-pad.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.str-pad" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">str_pad</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.1, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">str_pad</span> &mdash; <span class="dc-title">Pad a string to a certain length with another string</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.str-pad-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>str_pad</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$length</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$pad_string</code><span class="initializer"> = &quot; &quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$pad_type</code><span class="initializer"> = <strong><code><a href="string.constants.php#constant.str-pad-right">STR_PAD_RIGHT</a></code></strong></span></span><br>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   This function returns the <code class="parameter">string</code> string
   padded on the left, the right, or both sides to the specified
   padding length. If the optional argument
   <code class="parameter">pad_string</code> is not supplied, the
   <code class="parameter">string</code> is padded with spaces, otherwise it
   is padded with characters from <code class="parameter">pad_string</code>
   up to the limit.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.str-pad-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       The input string.
      </p>
     </dd>
    
    
     <dt><code class="parameter">length</code></dt>
     <dd>
      <p class="para">
       The desired length of the final padded string.
       If the value of <code class="parameter">length</code> is negative,
       less than, or equal to the length of the input string, no padding
       takes place, and <code class="parameter">string</code> will be returned.
      </p>
     </dd>
    
    
     <dt><code class="parameter">pad_string</code></dt>
     <dd>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        The <code class="parameter">pad_string</code> may be truncated if the
        required number of padding characters can&#039;t be evenly divided by the
        <code class="parameter">pad_string</code>&#039;s length.
       </p>
      </p></blockquote>
     </dd>
    
    
     <dt><code class="parameter">pad_type</code></dt>
     <dd>
      <p class="para">
       Optional argument <code class="parameter">pad_type</code> can be
       <strong><code><a href="string.constants.php#constant.str-pad-right">STR_PAD_RIGHT</a></code></strong>, <strong><code><a href="string.constants.php#constant.str-pad-left">STR_PAD_LEFT</a></code></strong>,
       or <strong><code><a href="string.constants.php#constant.str-pad-both">STR_PAD_BOTH</a></code></strong>. If
       <code class="parameter">pad_type</code> is not specified it is assumed to be
       <strong><code><a href="string.constants.php#constant.str-pad-right">STR_PAD_RIGHT</a></code></strong>.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.str-pad-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the padded string.
  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-function.str-pad-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>str_pad()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$input </span><span style="color: #007700">= </span><span style="color: #DD0000">"Alien"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">str_pad</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">, </span><span style="color: #0000BB">10</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;                      </span><span style="color: #FF8000">// produces "Alien     "<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">str_pad</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">, </span><span style="color: #0000BB">10</span><span style="color: #007700">, </span><span style="color: #DD0000">"-="</span><span style="color: #007700">, </span><span style="color: #0000BB">STR_PAD_LEFT</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;  </span><span style="color: #FF8000">// produces "-=-=-Alien"<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">str_pad</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">, </span><span style="color: #0000BB">10</span><span style="color: #007700">, </span><span style="color: #DD0000">"_"</span><span style="color: #007700">, </span><span style="color: #0000BB">STR_PAD_BOTH</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;   </span><span style="color: #FF8000">// produces "__Alien___"<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">str_pad</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">,  </span><span style="color: #0000BB">6</span><span style="color: #007700">, </span><span style="color: #DD0000">"___"</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;               </span><span style="color: #FF8000">// produces "Alien_"<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">str_pad</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">,  </span><span style="color: #0000BB">3</span><span style="color: #007700">, </span><span style="color: #DD0000">"*"</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;                 </span><span style="color: #FF8000">// produces "Alien"<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.str-pad-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.mb-str-pad.php" class="function" rel="rdfs-seeAlso">mb_str_pad()</a> - Pad a multibyte string to a certain length with another multibyte string</span></li>
   </ul>
  </p>
 </div>


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