Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 11818

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 file 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="splfileobject.fputcsv.html">SplFileObject::fputcsv</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="splfileobject.fseek.html">SplFileObject::fseek</a></div>
 <div class="up"><a href="class.splfileobject.html">SplFileObject</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="splfileobject.fscanf" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SplFileObject::fscanf</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0)</p><p class="refpurpose"><span class="refname">SplFileObject::fscanf</span> &mdash; <span class="dc-title">Parses input from file according to a format</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-splfileobject.fscanf-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>SplFileObject::fscanf</strong></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">
   Reads a line from the file 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 <em><code class="parameter">format</code></em> string matches any whitespace in the line from the file.
   This means that even a tab <em>\t</em> in the format string can match a single space character in the input stream.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-splfileobject.fscanf-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

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

      <p class="para">
       The specified format as described in the  <span class="function"><a href="function.sprintf.html" class="function">sprintf()</a></span> documentation.
      </p>
     </dd>

    </dt>

    <dt>

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

      <p class="para">
       The optional assigned values.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-splfileobject.fscanf-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   If only one parameter is passed to this method, 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" id="refsect1-splfileobject.fscanf-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-3958">
    <p><strong>Example #1  <span class="methodname"><strong>SplFileObject::fscanf()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$file&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SplFileObject</span><span style="color: #007700">(</span><span style="color: #DD0000">"misc.txt"</span><span style="color: #007700">);<br />while&nbsp;(</span><span style="color: #0000BB">$userinfo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$file</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fscanf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%s&nbsp;%s&nbsp;%s"</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;list&nbsp;(</span><span style="color: #0000BB">$name</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$profession</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$countrycode</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">$userinfo</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Do&nbsp;something&nbsp;with&nbsp;$name&nbsp;$professi<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>Contents of users.txt</p></div>
    <div class="example-contents">
<div class="txtcode"><pre class="txtcode">javier   argonaut    pe
hiroshi  sculptor    jp
robert   slacker     us
luigi    florist     it</pre>
</div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-splfileobject.fscanf-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>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="splfileobject.fputcsv.html">SplFileObject::fputcsv</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="splfileobject.fseek.html">SplFileObject::fseek</a></div>
 <div class="up"><a href="class.splfileobject.html">SplFileObject</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>