<?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.trim.php',
    1 => 'trim',
    2 => 'Strip whitespace (or other characters) from the beginning and end of a string',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String Функції',
  ),
  'prev' => 
  array (
    0 => 'function.substr-replace.php',
    1 => 'substr_replace',
  ),
  'next' => 
  array (
    0 => 'function.ucfirst.php',
    1 => 'ucfirst',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/strings/functions/trim.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.trim" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">trim</h1> 
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">trim</span> &mdash; <span class="dc-title">Strip whitespace (or other characters) from the beginning and end of a string</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.trim-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>trim</strong></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="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$characters</code><span class="initializer"> = &quot; \n\r\t\v\x00&quot;</span></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="simpara">
   This function returns a string with whitespace stripped from the
   beginning and end of <code class="parameter">string</code>.
   Without the second parameter,
   <span class="function"><strong>trim()</strong></span> will strip these characters:
  </p>
  
 <ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">
      <code class="literal">&quot; &quot;</code>: символ <abbr title="American Standard Code for Information Interchange">ASCII</abbr>
      <abbr>SP</abbr> <code class="literal">0x20</code>, звичайний пропуск.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <code class="literal">&quot;\t&quot;</code>: символ <abbr title="American Standard Code for Information Interchange">ASCII</abbr>
      <abbr>HT</abbr> <code class="literal">0x09</code>, табуляція.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <code class="literal">&quot;\n&quot;</code>: символ <abbr title="American Standard Code for Information Interchange">ASCII</abbr>
      <abbr>LF</abbr> <code class="literal">0x0A</code>, новий рядок.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <code class="literal">&quot;\r&quot;</code>: символ <abbr title="American Standard Code for Information Interchange">ASCII</abbr>
      <abbr>CR</abbr> <code class="literal">0x0D</code>, повернення каретки.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <code class="literal">&quot;\0&quot;</code>: символ <abbr title="American Standard Code for Information Interchange">ASCII</abbr>
      <abbr>NUL</abbr> <code class="literal">0x00</code>, NUL-байт.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <code class="literal">&quot;\v&quot;</code>: символ <abbr title="American Standard Code for Information Interchange">ASCII</abbr>
      <abbr>VT</abbr> <code class="literal">0x0B</code>, вертикальна табуляція.
     </span>
    </li>
   </ul>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.trim-parameters">
  <h3 class="title">Параметри</h3>
  <dl>
   
    <dt><code class="parameter">string</code></dt>
    <dd>
     <p class="para">
      The <span class="type"><a href="language.types.string.php" class="type string">string</a></span> that will be trimmed.
     </p>
    </dd>
   
   
    <dt><code class="parameter">characters</code></dt>
    <dd>
     
 <span class="simpara">
  Символи, що треба вилучити, можна вказати за допомогою необов&#039;язкового
  параметра <code class="parameter">characters</code>. Необхідно просто записати туди
  усі непотрібні символи. За допомогою <code class="literal">..</code> можна задати
  діапазон символів за зростанням.
 </span>

    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.trim-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="simpara">
   The trimmed string.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.trim-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 Usage example of <span class="function"><strong>trim()</strong></span></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$text   </span><span style="color: #007700">= </span><span style="color: #DD0000">"\t\tThese are a few words :) ...  "</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$binary </span><span style="color: #007700">= </span><span style="color: #DD0000">"\x09Example string\x0A"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$hello  </span><span style="color: #007700">= </span><span style="color: #DD0000">"Hello World"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$text</span><span style="color: #007700">, </span><span style="color: #0000BB">$binary</span><span style="color: #007700">, </span><span style="color: #0000BB">$hello</span><span style="color: #007700">);<br /><br />print </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$trimmed </span><span style="color: #007700">= </span><span style="color: #0000BB">trim</span><span style="color: #007700">(</span><span style="color: #0000BB">$text</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$trimmed</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$trimmed </span><span style="color: #007700">= </span><span style="color: #0000BB">trim</span><span style="color: #007700">(</span><span style="color: #0000BB">$text</span><span style="color: #007700">, </span><span style="color: #DD0000">" \t."</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$trimmed</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$trimmed </span><span style="color: #007700">= </span><span style="color: #0000BB">trim</span><span style="color: #007700">(</span><span style="color: #0000BB">$hello</span><span style="color: #007700">, </span><span style="color: #DD0000">"Hdle"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$trimmed</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$trimmed </span><span style="color: #007700">= </span><span style="color: #0000BB">trim</span><span style="color: #007700">(</span><span style="color: #0000BB">$hello</span><span style="color: #007700">, </span><span style="color: #DD0000">'HdWr'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$trimmed</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// trim the ASCII control characters at the beginning and end of $binary<br />// (from 0 to 31 inclusive)<br /></span><span style="color: #0000BB">$clean </span><span style="color: #007700">= </span><span style="color: #0000BB">trim</span><span style="color: #007700">(</span><span style="color: #0000BB">$binary</span><span style="color: #007700">, </span><span style="color: #DD0000">"\x00..\x1F"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$clean</span><span style="color: #007700">);<br /><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">string(32) &quot;        These are a few words :) ...  &quot;
string(16) &quot;    Example string
&quot;
string(11) &quot;Hello World&quot;

string(28) &quot;These are a few words :) ...&quot;
string(24) &quot;These are a few words :)&quot;
string(5) &quot;o Wor&quot;
string(9) &quot;ello Worl&quot;
string(14) &quot;Example string&quot;</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Приклад #2 Trimming array values with <span class="function"><strong>trim()</strong></span></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">function </span><span style="color: #0000BB">trim_value</span><span style="color: #007700">(&amp;</span><span style="color: #0000BB">$value</span><span style="color: #007700">) <br />{ <br />    </span><span style="color: #0000BB">$value </span><span style="color: #007700">= </span><span style="color: #0000BB">trim</span><span style="color: #007700">(</span><span style="color: #0000BB">$value</span><span style="color: #007700">); <br />}<br /><br /></span><span style="color: #0000BB">$fruit </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'apple'</span><span style="color: #007700">,</span><span style="color: #DD0000">'banana '</span><span style="color: #007700">, </span><span style="color: #DD0000">' cranberry '</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$fruit</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">array_walk</span><span style="color: #007700">(</span><span style="color: #0000BB">$fruit</span><span style="color: #007700">, </span><span style="color: #DD0000">'trim_value'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$fruit</span><span style="color: #007700">);<br /><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">array(3) {
  [0]=&gt;
  string(5) &quot;apple&quot;
  [1]=&gt;
  string(7) &quot;banana &quot;
  [2]=&gt;
  string(11) &quot; cranberry &quot;
}
array(3) {
  [0]=&gt;
  string(5) &quot;apple&quot;
  [1]=&gt;
  string(6) &quot;banana&quot;
  [2]=&gt;
  string(9) &quot;cranberry&quot;
}</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.trim-notes">
  <h3 class="title">Примітки</h3>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <strong>Possible gotcha: removing middle characters</strong><br />
   <p class="para">
    Because <span class="function"><strong>trim()</strong></span> trims characters from the beginning and end of
    a <span class="type"><a href="language.types.string.php" class="type string">string</a></span>, it may be confusing when characters are (or are not) removed from
    the middle. <code class="literal">trim(&#039;abc&#039;, &#039;bad&#039;)</code> removes both &#039;a&#039; and &#039;b&#039; because it
    trims &#039;a&#039; thus moving &#039;b&#039; to the beginning to also be trimmed. So, this is why it &quot;works&quot;
    whereas <code class="literal">trim(&#039;abc&#039;, &#039;b&#039;)</code> seemingly does not.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.trim-seealso">
  <h3 class="title">Прогляньте також</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.ltrim.php" class="function" rel="rdfs-seeAlso">ltrim()</a> - Strip whitespace (or other characters) from the beginning of a string</span></li>
   <li><span class="function"><a href="function.rtrim.php" class="function" rel="rdfs-seeAlso">rtrim()</a> - Strip whitespace (or other characters) from the end of a string</span></li>
   <li><span class="function"><a href="function.str-replace.php" class="function" rel="rdfs-seeAlso">str_replace()</a> - Replace all occurrences of the search string with the replacement string</span></li>
  </ul>
 </div>

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