<!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>Find length of initial segment not matching mask</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.strcoll.html">strcoll</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.strip-tags.html">strip_tags</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.strcspn" class="refentry"> <div class="refnamediv"> <h1 class="refname">strcspn</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">strcspn</span> — <span class="dc-title">Find length of initial segment not matching mask</span></p> </div> <div class="refsect1 description" id="refsect1-function.strcspn-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><strong>strcspn</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$str1</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$str2</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"> Returns the length of the initial segment of <em><code class="parameter">str1</code></em> which does <em class="emphasis">not</em> contain any of the characters in <em><code class="parameter">str2</code></em>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.strcspn-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">str1</code></em></span> <dd> <p class="para"> The first string. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">str2</code></em></span> <dd> <p class="para"> The second string. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">start</code></em></span> <dd> <p class="para"> The start position of the string to examine. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">length</code></em></span> <dd> <p class="para"> The length of the string to examine. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.strcspn-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the length of the segment as an integer. </p> </div> <div class="refsect1 changelog" id="refsect1-function.strcspn-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>4.3.0</td> <td> The <em><code class="parameter">start</code></em> and <em><code class="parameter">length</code></em> were added </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.strcspn-examples"> <h3 class="title">Examples</h3> <div class="example" id="strcspn.example"> <p><strong>Example #1 <span class="function"><strong>strcspn()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$a </span><span style="color: #007700">= </span><span style="color: #0000BB">strcspn</span><span style="color: #007700">(</span><span style="color: #DD0000">'abcd'</span><span style="color: #007700">, </span><span style="color: #DD0000">'apple'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$b </span><span style="color: #007700">= </span><span style="color: #0000BB">strcspn</span><span style="color: #007700">(</span><span style="color: #DD0000">'abcd'</span><span style="color: #007700">, </span><span style="color: #DD0000">'banana'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$c </span><span style="color: #007700">= </span><span style="color: #0000BB">strcspn</span><span style="color: #007700">(</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">, </span><span style="color: #DD0000">'l'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$d </span><span style="color: #007700">= </span><span style="color: #0000BB">strcspn</span><span style="color: #007700">(</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">, </span><span style="color: #DD0000">'world'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$b</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$d</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></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(0) int(2) int(2) </pre></div> </div> </div> </div> <div class="refsect1 notes" id="refsect1-function.strcspn-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.strcspn-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.strspn.html" class="function" rel="rdfs-seeAlso">strspn()</a> - Finds the length of the initial segment of a string consisting entirely of characters contained within a given 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.strcoll.html">strcoll</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.strip-tags.html">strip_tags</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>