Sophie

Sophie

distrib > Mageia > 7 > aarch64 > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 6651

php-manual-en-7.2.11-1.mga7.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Finds the length of the initial segment of a string consisting
   entirely of characters contained within a given mask</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.strrpos.html">strrpos</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.strstr.html">strstr</a></div>
 <div class="up"><a href="ref.strings.html">String Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.strspn" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">strspn</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</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">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">int</span> <span class="methodname"><strong>strspn</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$subject</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$mask</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$start</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$length</code></span>
  ]] )</div>

  <p class="para rdfs-comment">
   Finds the length of the initial segment of <code class="parameter">subject</code>
   that contains <em class="emphasis">only</em> characters from <code class="parameter">mask</code>.
  </p>
  <p class="para">
   If <code class="parameter">start</code> and <code class="parameter">length</code>
   are omitted, then all of <code class="parameter">subject</code> will be
   examined. If they are included, then the effect will be the same as
   calling <em>strspn(substr($subject, $start, $length),
   $mask)</em> (see <a href="function.substr.html" class="xref">substr</a>
   for more information).
  </p>
  <p class="para">
   The line of code:
   <div class="informalexample">
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$var&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strspn</span><span style="color: #007700">(</span><span style="color: #DD0000">"42&nbsp;is&nbsp;the&nbsp;answer&nbsp;to&nbsp;the&nbsp;128th&nbsp;question."</span><span style="color: #007700">,&nbsp;</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 <em>2</em> to <var class="varname"><var class="varname">$var</var></var>,
   because the string &quot;42&quot; is the initial segment
   of <code class="parameter">subject</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">Parameters</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">subject</code></dt>

     <dd>

      <p class="para">
       The string to examine.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">mask</code></dt>

     <dd>

      <p class="para">
       The list of allowable characters.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">start</code></dt>

     <dd>

      <p class="para">
       The position in <code class="parameter">subject</code> to
       start searching.
      </p>
      <p class="para">
       If <code class="parameter">start</code> is given and is non-negative,
       then <span class="function"><strong>strspn()</strong></span> will begin
       examining <code class="parameter">subject</code> at
       the <code class="parameter">start</code>&#039;th position. For instance, in
       the string &#039;<em>abcdef</em>&#039;, the character at
       position <em>0</em> is &#039;<em>a</em>&#039;, the
       character at position <em>2</em> is
       &#039;<em>c</em>&#039;, and so forth.
      </p>
      <p class="para">
       If <code class="parameter">start</code> is given and is negative,
       then <span class="function"><strong>strspn()</strong></span> will begin
       examining <code class="parameter">subject</code> at
       the <code class="parameter">start</code>&#039;th position from the end
       of <code class="parameter">subject</code>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">length</code></dt>

     <dd>

      <p class="para">
       The length of the segment from <code class="parameter">subject</code>
       to examine. 
      </p>
      <p class="para">
       If <code class="parameter">length</code> is given and is non-negative,
       then <code class="parameter">subject</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">subject</code> will be examined from the
        starting position up to <code class="parameter">length</code>
        characters from the end of <code class="parameter">subject</code>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.strspn-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the length of the initial segment of <code class="parameter">subject</code>
   which consists entirely of characters in <code class="parameter">mask</code>.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    When a <code class="parameter">start</code> parameter is set, the returned length
    is counted starting from this position, not from the beginning of
    <code class="parameter">subject</code>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 examples" id="refsect1-function.strspn-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-6112">
    <p><strong>Example #1 <span class="function"><strong>strspn()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;subject&nbsp;does&nbsp;not&nbsp;start&nbsp;with&nbsp;any&nbsp;characters&nbsp;from&nbsp;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">,&nbsp;</span><span style="color: #DD0000">"o"</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;examine&nbsp;two&nbsp;characters&nbsp;from&nbsp;subject&nbsp;starting&nbsp;at&nbsp;offset&nbsp;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">,&nbsp;</span><span style="color: #DD0000">"o"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;examine&nbsp;one&nbsp;character&nbsp;from&nbsp;subject&nbsp;starting&nbsp;at&nbsp;offset&nbsp;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">,&nbsp;</span><span style="color: #DD0000">"o"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</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>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
int(0)
int(2)
int(1)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.strspn-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">This function is
binary-safe.</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.strspn-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.strcspn.html" class="function" rel="rdfs-seeAlso">strcspn()</a> - Find length of initial segment not matching mask</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.strrpos.html">strrpos</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.strstr.html">strstr</a></div>
 <div class="up"><a href="ref.strings.html">String Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>