Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 5916

php-manual-en-5.5.7-1.mga4.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>Parses input from a string according to a format</title>

 </head>
 <body><div class="manualnavbar" 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" id="refsect1-function.sscanf-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"><strong>sscanf</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$str</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$format</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter reference">&$...</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   The function  <span class="function"><strong>sscanf()</strong></span> is the input analog of
    <span class="function"><a href="function.printf.html" class="function">printf()</a></span>.  <span class="function"><strong>sscanf()</strong></span> reads
   from the string <em><code class="parameter">str</code></em> and interprets it
   according to the specified <em><code class="parameter">format</code></em>, which is
   described in the documentation for  <span class="function"><a href="function.sprintf.html" class="function">sprintf()</a></span>. 
  </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" id="refsect1-function.sscanf-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">str</code></em></span>
     <dd>

      <p class="para">
       The input <span class="type"><a href="language.types.string.html" class="type string">string</a></span> being parsed.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">format</code></em></span>
     <dd>

      <p class="para">
       The interpreted format for <em><code class="parameter">str</code></em>, which is
       described in the documentation for  <span class="function"><a href="function.sprintf.html" class="function">sprintf()</a></span> with
       following differences:
       <ul class="simplelist">
        <li class="member">
         Function is not locale-aware.
        </li>
        <li class="member">
         <em>F</em>, <em>g</em>, <em>G</em> and
         <em>b</em> are not supported.
        </li>
        <li class="member">
         <em>D</em> stands for decimal number.
        </li>
        <li class="member">
         <em>i</em> stands for integer with base detection.
        </li>
        <li class="member">
         <em>n</em> stands for number of characters processed so far.
        </li>
       </ul>
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">...</code></em></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" id="refsect1-function.sscanf-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>
  <p class="para">
   If there are more substrings expected in the <em><code class="parameter">format</code></em>
   than there are available within <em><code class="parameter">str</code></em>,
   <em>-1</em> will be returned.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.sscanf-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-4873">
    <p><strong>Example #1  <span class="function"><strong>sscanf()</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;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;</span><span style="color: #0000BB">$serial</span><span style="color: #DD0000">&nbsp;was&nbsp;manufactured&nbsp;on:&nbsp;</span><span style="color: #0000BB">$year</span><span style="color: #DD0000">-"&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">"-</span><span style="color: #0000BB">$day</span><span style="color: #DD0000">\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" id="example-4874">
    <p><strong>Example #2  <span class="function"><strong>sscanf()</strong></span> - using optional parameters</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;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='</span><span style="color: #0000BB">$id</span><span style="color: #DD0000">'&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;firstname&gt;</span><span style="color: #0000BB">$first</span><span style="color: #DD0000">&lt;/firstname&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;surname&gt;</span><span style="color: #0000BB">$last</span><span style="color: #DD0000">&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" id="refsect1-function.sscanf-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.fscanf.html" class="function" rel="rdfs-seeAlso">fscanf()</a> - Parses input from a file according to a format</span></li>
    <li class="member"> <span class="function"><a href="function.printf.html" class="function" rel="rdfs-seeAlso">printf()</a> - Output a formatted string</span></li>
    <li class="member"> <span class="function"><a href="function.sprintf.html" class="function" rel="rdfs-seeAlso">sprintf()</a> - Return a formatted string</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.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>