<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.sscanf.php',
    1 => 'sscanf',
    2 => 'Parses input from a string according to a format',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String Functions',
  ),
  'prev' => 
  array (
    0 => 'function.sprintf.php',
    1 => 'sprintf',
  ),
  'next' => 
  array (
    0 => 'function.str-contains.php',
    1 => 'str_contains',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/strings/functions/sscanf.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<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, PHP 7, PHP 8)</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="modifier">function</span> <span class="methodname"><strong>sscanf</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$format</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter reference">&...$vars</code></span>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.null.php" class="type null">null</a></span></span></div>

  <p class="simpara">
   The function <span class="function"><strong>sscanf()</strong></span> is the input analog of
   <span class="function"><a href="function.printf.php" class="function">printf()</a></span>. <span class="function"><strong>sscanf()</strong></span> reads
   from the string <code class="parameter">string</code> and interprets it
   according to the specified <code class="parameter">format</code>. 
  </p>
  <p class="simpara">
   Any whitespace in the format string matches any whitespace in the input
   string. This means that even a tab (<code class="literal">\t</code>) 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>
  <dl>
   
    <dt><code class="parameter">string</code></dt>
    <dd>
     <span class="simpara">
      The input <span class="type"><a href="language.types.string.php" class="type string">string</a></span> being parsed.
     </span>
    </dd>
   
   

     <dt><code class="parameter">format</code></dt>
     <dd>
      <p class="para">
       The interpreted format for <code class="parameter">string</code>, which is
       described in the documentation for <span class="function"><a href="function.sprintf.php" class="function">sprintf()</a></span> with
       following differences:
       <ul class="simplelist">
        <li>
         Function is not locale-aware.
        </li>
        <li>
         <code class="literal">F</code>, <code class="literal">g</code>, <code class="literal">G</code> and
         <code class="literal">b</code> are not supported.
        </li>
        <li>
         <code class="literal">D</code> stands for decimal number.
        </li>
        <li>
         <code class="literal">i</code> stands for integer with base detection.
        </li>
        <li>
         <code class="literal">n</code> stands for number of characters processed so far.
        </li>
        <li>
         <code class="literal">s</code> stops reading at any whitespace character.
        </li>
        <li>
         <code class="literal">*</code> instead of <code class="literal">argnum$</code> suppresses
         the assignment of this conversion specification.
        </li>
       </ul>
      </p>
     </dd>
    

   
    <dt><code class="parameter">vars</code></dt>
    <dd>
     <span class="simpara">
      Optionally pass in variables by reference that will contain the parsed values.
     </span>
    </dd>
   
  </dl>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.sscanf-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="simpara">
   If only two parameters were passed to this function, the values parsed will
   be returned as an <span class="type"><a href="language.types.array.php" class="type array">array</a></span>. 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="simpara">
   If there are more substrings expected in the <code class="parameter">format</code>
   than there are available within <code class="parameter">string</code>,
   <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> will be returned.
  </p>
  <p class="simpara">
   When optional parameters are used and the end of the input
   <code class="parameter">string</code> is reached before any value has been
   parsed, <code class="literal">-1</code> is returned.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.sscanf-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="function"><strong>sscanf()</strong></span> Example</strong></p>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// getting the serial number<br /></span><span style="color: #007700">list(</span><span style="color: #0000BB">$serial</span><span style="color: #007700">) = </span><span style="color: #0000BB">sscanf</span><span style="color: #007700">(</span><span style="color: #DD0000">"SN/2350001"</span><span style="color: #007700">, </span><span style="color: #DD0000">"SN/%d"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// and the date of manufacturing<br /></span><span style="color: #0000BB">$mandate </span><span style="color: #007700">= </span><span style="color: #DD0000">"January 01 2000"</span><span style="color: #007700">;<br />list(</span><span style="color: #0000BB">$month</span><span style="color: #007700">, </span><span style="color: #0000BB">$day</span><span style="color: #007700">, </span><span style="color: #0000BB">$year</span><span style="color: #007700">) = </span><span style="color: #0000BB">sscanf</span><span style="color: #007700">(</span><span style="color: #0000BB">$mandate</span><span style="color: #007700">, </span><span style="color: #DD0000">"%s %d %d"</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Item </span><span style="color: #0000BB">$serial</span><span style="color: #DD0000"> was manufactured on: </span><span style="color: #0000BB">$year</span><span style="color: #DD0000">-" </span><span style="color: #007700">. </span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$month</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">3</span><span style="color: #007700">) . </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 class="simpara">
   If optional parameters are passed, the function will return the
   number of assigned values.
  </p>
  <div class="example" id="example-2">
   <p><strong>Example #2 <span class="function"><strong>sscanf()</strong></span> - using optional parameters</strong></p>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// get author info and generate DocBook entry<br /></span><span style="color: #0000BB">$auth </span><span style="color: #007700">= </span><span style="color: #DD0000">"24\tLewis Carroll"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$n </span><span style="color: #007700">= </span><span style="color: #0000BB">sscanf</span><span style="color: #007700">(</span><span style="color: #0000BB">$auth</span><span style="color: #007700">, </span><span style="color: #DD0000">"%d\t%s %s"</span><span style="color: #007700">, </span><span style="color: #0000BB">$id</span><span style="color: #007700">, </span><span style="color: #0000BB">$first</span><span style="color: #007700">, </span><span style="color: #0000BB">$last</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"&lt;author id='</span><span style="color: #0000BB">$id</span><span style="color: #DD0000">'&gt;<br />    &lt;firstname&gt;</span><span style="color: #0000BB">$first</span><span style="color: #DD0000">&lt;/firstname&gt;<br />    &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>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.sscanf-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.printf.php" class="function" rel="rdfs-seeAlso">printf()</a> - Output a formatted string</span></li>
   <li><span class="function"><a href="function.sprintf.php" class="function" rel="rdfs-seeAlso">sprintf()</a> - Return a formatted string</span></li>
   <li><span class="function"><a href="function.fprintf.php" class="function" rel="rdfs-seeAlso">fprintf()</a> - Write a formatted string to a stream</span></li>
   <li><span class="function"><a href="function.vprintf.php" class="function" rel="rdfs-seeAlso">vprintf()</a> - Output a formatted string</span></li>
   <li><span class="function"><a href="function.vsprintf.php" class="function" rel="rdfs-seeAlso">vsprintf()</a> - Return a formatted string</span></li>
   <li><span class="function"><a href="function.vfprintf.php" class="function" rel="rdfs-seeAlso">vfprintf()</a> - Write a formatted string to a stream</span></li>
   <li><span class="function"><a href="function.fscanf.php" class="function" rel="rdfs-seeAlso">fscanf()</a> - Parses input from a file according to a format</span></li>
   <li><span class="function"><a href="function.number-format.php" class="function" rel="rdfs-seeAlso">number_format()</a> - Format a number with grouped thousands</span></li>
   <li><span class="function"><a href="function.date.php" class="function" rel="rdfs-seeAlso">date()</a> - Format a Unix timestamp</span></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>