<?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.strspn.php',
    1 => 'strspn',
    2 => 'Finds the length of the initial segment of a string consisting
   entirely of characters contained within a given mask',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String Функції',
  ),
  'prev' => 
  array (
    0 => 'function.strrpos.php',
    1 => 'strrpos',
  ),
  'next' => 
  array (
    0 => 'function.strstr.php',
    1 => 'strstr',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/strings/functions/strspn.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.strspn" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">strspn</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">strspn</span> &mdash; <span class="dc-title">
   Finds the length of the initial segment of a string consisting
   entirely of characters contained within a given mask
  </span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.strspn-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>strspn</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.string.php" class="type string">string</a></span> <code class="parameter">$characters</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">$offset</code><span class="initializer"> = 0</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$length</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

  <p class="para rdfs-comment">
   Finds the length of the initial segment of <code class="parameter">string</code>
   that contains <em>only</em> characters from <code class="parameter">characters</code>.
  </p>
  <p class="para">
   If <code class="parameter">offset</code> and <code class="parameter">length</code>
   are omitted, then all of <code class="parameter">string</code> will be
   examined. If they are included, then the effect will be the same as
   calling <code class="literal">strspn(substr($string, $offset, $length),
   $characters)</code> (see <a href="function.substr.php" class="xref">substr</a>
   for more information).
  </p>
  <p class="para">
   The line of code:
   <div class="informalexample">
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$var </span><span style="color: #007700">= </span><span style="color: #0000BB">strspn</span><span style="color: #007700">(</span><span style="color: #DD0000">"42 is the answer to the 128th question."</span><span style="color: #007700">, </span><span style="color: #DD0000">"1234567890"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
   will assign <code class="literal">2</code> to <var class="varname">$var</var>,
   because the string &quot;42&quot; is the initial segment
   of <code class="parameter">string</code> that consists only of characters
   contained within &quot;1234567890&quot;.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.strspn-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       The string to examine.
      </p>
     </dd>
    
    
     <dt><code class="parameter">characters</code></dt>
     <dd>
      <p class="para">
       The list of allowable characters.
      </p>
     </dd>
    
    
     <dt><code class="parameter">offset</code></dt>
     <dd>
      <p class="para">
       The position in <code class="parameter">string</code> to
       start searching.
      </p>
      <p class="para">
       If <code class="parameter">offset</code> is given and is non-negative,
       then <span class="function"><strong>strspn()</strong></span> will begin
       examining <code class="parameter">string</code> at
       the <code class="parameter">offset</code>&#039;th position. For instance, in
       the string &#039;<code class="literal">abcdef</code>&#039;, the character at
       position <code class="literal">0</code> is &#039;<code class="literal">a</code>&#039;, the
       character at position <code class="literal">2</code> is
       &#039;<code class="literal">c</code>&#039;, and so forth.
      </p>
      <p class="para">
       If <code class="parameter">offset</code> is given and is negative,
       then <span class="function"><strong>strspn()</strong></span> will begin
       examining <code class="parameter">string</code> at
       the <code class="parameter">offset</code>&#039;th position from the end
       of <code class="parameter">string</code>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">length</code></dt>
     <dd>
      <p class="para">
       The length of the segment from <code class="parameter">string</code>
       to examine. 
      </p>
      <p class="para">
       If <code class="parameter">length</code> is given and is non-negative,
       then <code class="parameter">string</code> will be examined
       for <code class="parameter">length</code> characters after the starting
       position.
      </p>
      <p class="para">
        If <code class="parameter">length</code> is given and is negative,
        then <code class="parameter">string</code> will be examined from the
        starting position up to <code class="parameter">length</code>
        characters from the end of <code class="parameter">string</code>.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.strspn-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns the length of the initial segment of <code class="parameter">string</code>
   which consists entirely of characters in <code class="parameter">characters</code>.
  </p>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <p class="para">
    When a <code class="parameter">offset</code> parameter is set, the returned length
    is counted starting from this position, not from the beginning of
    <code class="parameter">string</code>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.strspn-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>
       <code class="parameter">length</code> is nullable now.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.strspn-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 <span class="function"><strong>strspn()</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 /></span><span style="color: #FF8000">// subject does not start with any characters from mask<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">strspn</span><span style="color: #007700">(</span><span style="color: #DD0000">"foo"</span><span style="color: #007700">, </span><span style="color: #DD0000">"o"</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// examine two characters from subject starting at offset 1<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">strspn</span><span style="color: #007700">(</span><span style="color: #DD0000">"foo"</span><span style="color: #007700">, </span><span style="color: #DD0000">"o"</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// examine one character from subject starting at offset 1<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">strspn</span><span style="color: #007700">(</span><span style="color: #DD0000">"foo"</span><span style="color: #007700">, </span><span style="color: #DD0000">"o"</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">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">int(0)
int(2)
int(1)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.strspn-notes">
  <h3 class="title">Примітки</h3>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: <span class="simpara">Ця функція є бінарно
безпечною.</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.strspn-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.strcspn.php" class="function" rel="rdfs-seeAlso">strcspn()</a> - Find length of initial segment not matching mask</span></li>
   </ul>
  </p>
 </div>


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