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

contributors($setup);

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

 </div>
 
 <div class="refsect1 description" id="refsect1-function.strtok-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>strtok</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">$token</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>

  <p class="simpara">Alternative signature (not supported with named arguments):</p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>strtok</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$token</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>

  <p class="para rdfs-comment">
   <span class="function"><strong>strtok()</strong></span> splits a string (<code class="parameter">string</code>)
   into smaller strings (tokens), with each token being delimited by any
   character from <code class="parameter">token</code>.
   That is, if you have a string like &quot;This is an example string&quot; you
   could tokenize this string into its individual words by using the
   space character as the <code class="parameter">token</code>.
  </p>
  <p class="para">
   Note that only the first call to strtok uses the <code class="parameter">string</code> argument.
   Every subsequent call to strtok only needs the <code class="parameter">token</code> to use, as
   it keeps track of where it is in the current string.  To start
   over, or to tokenize a new string you simply call strtok with the
   <code class="parameter">string</code> argument again to initialize it.  Note that you may put
   multiple tokens in the <code class="parameter">token</code> parameter.  The string will be
   tokenized when any one of the characters in the <code class="parameter">token</code> argument is
   found.
  </p>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <p class="para">
    This function behaves slightly different from what one may expect being
    familiar with <span class="function"><a href="function.explode.php" class="function">explode()</a></span>. 
    First, a sequence of two or more contiguous <code class="parameter">token</code>
    characters in the parsed string is considered to be a single delimiter. 
    Also, a <code class="parameter">token</code> situated at the start or end of the
    string is ignored.
    For example, if a string <code class="literal">&quot;;aaa;;bbb;&quot;</code> is used, successive
    calls to <span class="function"><strong>strtok()</strong></span> with <code class="literal">&quot;;&quot;</code> as a
    <code class="parameter">token</code> would return strings
    &quot;aaa&quot; and &quot;bbb&quot;, and then <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
    As a result, the string will be split into only two elements, while
    <code class="literal">explode(&quot;;&quot;, $string)</code> would return an array of 5 elements.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.strtok-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <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> being split up into smaller strings (tokens).
      </p>
     </dd>
    
    
     <dt><code class="parameter">token</code></dt>
     <dd>
      <p class="para">
       The delimiter used when splitting up <code class="parameter">string</code>.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.strtok-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   A <span class="type"><a href="language.types.string.php" class="type string">string</a></span> token, or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> if no more tokens are available.
  </p>
 </div>


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

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.3.0</td>
       <td>
        Now emits <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> when <code class="parameter">token</code> is not provided.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.strtok-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 <span class="function"><strong>strtok()</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 />$string </span><span style="color: #007700">= </span><span style="color: #DD0000">"This is\tan example\nstring"</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">/* Use tab and newline as tokenizing characters as well  */<br /></span><span style="color: #0000BB">$tok </span><span style="color: #007700">= </span><span style="color: #0000BB">strtok</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">, </span><span style="color: #DD0000">" \n\t"</span><span style="color: #007700">);<br /><br />while (</span><span style="color: #0000BB">$tok </span><span style="color: #007700">!== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"Word=</span><span style="color: #007700">{</span><span style="color: #0000BB">$tok</span><span style="color: #007700">}</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />    </span><span style="color: #0000BB">$tok </span><span style="color: #007700">= </span><span style="color: #0000BB">strtok</span><span style="color: #007700">(</span><span style="color: #DD0000">" \n\t"</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Приклад #2 <span class="function"><strong>strtok()</strong></span> behavior on empty part found</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$first_token  </span><span style="color: #007700">= </span><span style="color: #0000BB">strtok</span><span style="color: #007700">(</span><span style="color: #DD0000">'/something'</span><span style="color: #007700">, </span><span style="color: #DD0000">'/'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$second_token </span><span style="color: #007700">= </span><span style="color: #0000BB">strtok</span><span style="color: #007700">(</span><span style="color: #DD0000">'/'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$first_token</span><span style="color: #007700">, </span><span style="color: #0000BB">$second_token</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">string(9) &quot;something&quot;
    bool(false)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-3">
    <p><strong>Приклад #3 The difference between <span class="function"><strong>strtok()</strong></span> and <span class="function"><a href="function.explode.php" class="function">explode()</a></span></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$string </span><span style="color: #007700">= </span><span style="color: #DD0000">";aaa;;bbb;"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$parts </span><span style="color: #007700">= [];<br /></span><span style="color: #0000BB">$tok </span><span style="color: #007700">= </span><span style="color: #0000BB">strtok</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">, </span><span style="color: #DD0000">";"</span><span style="color: #007700">);<br />while (</span><span style="color: #0000BB">$tok </span><span style="color: #007700">!== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />    </span><span style="color: #0000BB">$parts</span><span style="color: #007700">[] = </span><span style="color: #0000BB">$tok</span><span style="color: #007700">;<br />    </span><span style="color: #0000BB">$tok </span><span style="color: #007700">= </span><span style="color: #0000BB">strtok</span><span style="color: #007700">(</span><span style="color: #DD0000">";"</span><span style="color: #007700">);<br />}<br />echo </span><span style="color: #0000BB">json_encode</span><span style="color: #007700">(</span><span style="color: #0000BB">$parts</span><span style="color: #007700">),</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$parts </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: #0000BB">$string</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">json_encode</span><span style="color: #007700">(</span><span style="color: #0000BB">$parts</span><span style="color: #007700">),</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;</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">[&quot;aaa&quot;,&quot;bbb&quot;]
[&quot;&quot;,&quot;aaa&quot;,&quot;&quot;,&quot;bbb&quot;,&quot;&quot;]</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.strtok-notes">
  <h3 class="title">Примітки</h3>
  
  <div class="warning"><strong class="warning">Увага</strong><p class="simpara">Ця функція може
повертати як логічне <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, так і не логічне значення, яке прирівнюється до
<strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>. Докладніше про це описано в розділі <a href="language.types.boolean.php" class="link">Логічні типи даних</a>. Для перевірки
значення, яке повертає ця функція, використовується <a href="language.operators.comparison.php" class="link">оператор ===</a>.</p></div>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.strtok-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.explode.php" class="function" rel="rdfs-seeAlso">explode()</a> - Розбиває рядок на підрядки</span></li>
   </ul>
  </p>
 </div>


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