function.strspn.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 202 行
HTML
202 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Find length of initial segment matching mask</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div 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)</p><p class="refpurpose"><span class="refname">strspn</span> — <span class="dc-title">Find length of initial segment matching mask</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><b><b>strspn</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$str1</tt></span> , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$str2</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$start</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$length</tt></span> ]] )</div> <p class="para rdfs-comment"> Finds the length of the initial segment matching mask. </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"><?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, what is the question ..."</span><span style="color: #007700">, </span><span style="color: #DD0000">"1234567890"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> will assign 2 to <var class="varname">$var</var>, because the string "42" will be the longest segment containing characters from "1234567890". </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">str1</tt></i></span> <dd> <p class="para"> The first string. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">str2</tt></i></span> <dd> <p class="para"> The second string. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">start</tt></i></span> <dd> <p class="para"> The start position of the string to examine. Negative value counts position from the end of a string. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">length</tt></i></span> <dd> <p class="para"> The length of the string to examine. Negative value sets length from the end of a string. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the length of the initial segment of <i><tt class="parameter">str1</tt></i> which consists entirely of characters in <i><tt class="parameter">str2</tt></i>. </p> </div> <div class="refsect1 changelog"> <h3 class="title">ChangeLog</h3> <p class="para"> <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Version</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">4.3.0</td> <td colspan="1" rowspan="1" align="left"> The <i><tt class="parameter">start</tt></i> and <i><tt class="parameter">length</tt></i> parameters were added </td> </tr> </tbody> </colgroup> </table> </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>strspn()</b> example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">echo </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">); </span><span style="color: #FF8000">// 2<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 notes"> <h3 class="title">Notes</h3> <blockquote><p><b class="note">Note</b>: <span class="simpara">This function isbinary-safe.</span></p></blockquote> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.strcspn.html" class="function" rel="rdfs-seeAlso">strcspn()</a></li> </ul> </p> </div></div><hr /><div 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>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?