strcspn
Get the length of the starting substring that does not match the mask
Output the number of characters found before the character "w" is found in the string "Hello world!":
<span class="token php language-php"><span class="token delimiter important"><?php</span> <span class="token keyword">echo</span> <span class="token function">strcspn</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"Hello world!"</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"w"</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span> <span class="token delimiter important">?></span></span>
Use all parameters to output the number of characters that were found before the character "w" is found in the string "Hello world!":
<span class="token php language-php"><span class="token delimiter important"><?php</span> <span class="token keyword">echo</span> <span class="token function">strcspn</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"Hello world!"</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"w"</span> <span class="token punctuation">,</span> <span class="token number">0</span> <span class="token punctuation">,</span> <span class="token number">6</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span> <span class="token comment">// The start position is 0, and the length of the search string is 6.</span> <span class="token delimiter important">?></span></span>