⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.sscanf.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Parses input from a string according to a format</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.sprintf.html">sprintf</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.str-getcsv.html">str_getcsv</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.sscanf" class="refentry"> <div class="refnamediv">  <h1 class="refname">sscanf</h1>  <p class="verinfo">(PHP 4 &gt;= 4.0.1, PHP 5)</p><p class="refpurpose"><span class="refname">sscanf</span> &mdash; <span class="dc-title">Parses input from a string according to a format</span></p> </div>  <div class="refsect1 description">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><b><b>sscanf</b></b></span>    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$str</tt></span>   , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$format</tt></span>   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter reference">&$...</tt></span>  ] )</div>  <p class="para rdfs-comment">   The function <b>sscanf()</b> is the input analog of   <a href="function.printf.html" class="function">printf()</a>. <b>sscanf()</b> reads   from the string <i><tt class="parameter">str</tt></i> and interprets it   according to the specified <i><tt class="parameter">format</tt></i>, which is   described in the documentation for <a href="function.sprintf.html" class="function">sprintf()</a>.   </p>  <p class="para">   Any whitespace in the format string matches any whitespace in the input   string. This means that even a tab \t in the format string can match a   single space character in the input string.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">str</tt></i></span>     <dd>      <p class="para">       The input <a href="language.types.string.html" class="type string">string</a> being parsed.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">format</tt></i></span>     <dd>      <p class="para">       The interpreted format for <i><tt class="parameter">str</tt></i>, which is       described in the documentation for <a href="function.sprintf.html" class="function">sprintf()</a>.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">...</tt></i></span>     <dd>      <p class="para">       Optionally pass in variables by reference that will contain the parsed values.      </p>     </dd>    </dt>   </dl>  </p> </div>  <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   If only   two parameters were passed to this function, the values parsed   will be returned as an array. Otherwise, if optional parameters are passed,   the function will return the number of assigned values. The optional   parameters must be passed by reference.  </p> </div> <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 <b>sscanf()</b> Example</b></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;getting&nbsp;the&nbsp;serial&nbsp;number<br /></span><span style="color: #007700">list(</span><span style="color: #0000BB">$serial</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">sscanf</span><span style="color: #007700">(</span><span style="color: #DD0000">"SN/2350001"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SN/%d"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;and&nbsp;the&nbsp;date&nbsp;of&nbsp;manufacturing<br /></span><span style="color: #0000BB">$mandate&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"January&nbsp;01&nbsp;2000"</span><span style="color: #007700">;<br />list(</span><span style="color: #0000BB">$month</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$day</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$year</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">sscanf</span><span style="color: #007700">(</span><span style="color: #0000BB">$mandate</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"%s&nbsp;%d&nbsp;%d"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"Item&nbsp;$serial&nbsp;was&nbsp;manufactured&nbsp;on:&nbsp;$year-"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$month</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"-$day\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p>  <p class="para">   If optional parameters are passed, the function will return the   number of assigned values.  </p>  <p class="para">   <div class="example">    <p><b>Example #2 <b>sscanf()</b> - using optional parameters</b></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;get&nbsp;author&nbsp;info&nbsp;and&nbsp;generate&nbsp;DocBook&nbsp;entry<br /></span><span style="color: #0000BB">$auth&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"24\tLewis&nbsp;Carroll"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$n&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sscanf</span><span style="color: #007700">(</span><span style="color: #0000BB">$auth</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"%d\t%s&nbsp;%s"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$id</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$first</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$last</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"&lt;author&nbsp;id='$id'&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;firstname&gt;$first&lt;/firstname&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;surname&gt;$last&lt;/surname&gt;<br />&lt;/author&gt;\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p> </div> <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.fscanf.html" class="function" rel="rdfs-seeAlso">fscanf()</a></li>    <li class="member"><a href="function.printf.html" class="function" rel="rdfs-seeAlso">printf()</a></li>    <li class="member"><a href="function.sprintf.html" class="function" rel="rdfs-seeAlso">sprintf()</a></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sprintf.html">sprintf</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.str-getcsv.html">str_getcsv</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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -