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

📄 function.fseek.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>Seeks on a file pointer</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.fscanf.html">fscanf</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.fstat.html">fstat</a></div> <div class="up"><a href="ref.filesystem.html">Filesystem Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.fseek" class="refentry"> <div class="refnamediv">  <h1 class="refname">fseek</h1>  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">fseek</span> &mdash; <span class="dc-title">Seeks on a file pointer</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>fseek</b></b></span>    ( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$handle</tt></span>   , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$offset</tt></span>   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$whence</tt></span>  ] )</div>  <p class="para rdfs-comment">   Sets the file position indicator for the file referenced by   <i><tt class="parameter">handle</tt></i>. The new position, measured in bytes   from the beginning of the file, is obtained by adding   <i><tt class="parameter">offset</tt></i> to the position specified by   <i><tt class="parameter">whence</tt></i>.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">handle</tt></i></span>     <dd>      <p class="para">A file system pointer <a href="language.types.resource.html" class="type resource">resource</a>that is typically created using <a href="function.fopen.html" class="function">fopen()</a>.</p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">offset</tt></i></span>     <dd>      <p class="para">       The offset.      </p>      <p class="para">       To move to a position before the end-of-file, you need to pass a negative       value in <i><tt class="parameter">offset</tt></i>.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">whence</tt></i></span>     <dd>      <p class="para">       <i><tt class="parameter">whence</tt></i> values are:       <ul class="simplelist">        <li class="member"><b><tt>SEEK_SET</tt></b> - Set position equal to <i><tt class="parameter">offset</tt></i> bytes.</li>        <li class="member"><b><tt>SEEK_CUR</tt></b> - Set position to current location plus <i><tt class="parameter">offset</tt></i>.</li>        <li class="member"><b><tt>SEEK_END</tt></b> - Set position to end-of-file plus <i><tt class="parameter">offset</tt></i>.</li>       </ul>      </p>      <p class="para">       If <i><tt class="parameter">whence</tt></i> is not specified, it is assumed to be       <b><tt>SEEK_SET</tt></b>.      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   Upon success, returns 0; otherwise, returns -1. Note that seeking   past EOF is not considered an error.  </p> </div> <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 <b>fseek()</b> example</b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'somefile.txt'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'r'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;read&nbsp;some&nbsp;data<br /></span><span style="color: #0000BB">$data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fgets</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4096</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;move&nbsp;back&nbsp;to&nbsp;the&nbsp;beginning&nbsp;of&nbsp;the&nbsp;file<br />//&nbsp;same&nbsp;as&nbsp;rewind($fp);<br /></span><span style="color: #0000BB">fseek</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p> </div> <div class="refsect1 notes">  <h3 class="title">Notes</h3>  <blockquote><p><b class="note">Note</b>:        If you have opened the file in append (&quot;a&quot; or &quot;a+&quot;) mode, any data you write    to the file will always be appended, regardless of the file position.   <br />  </p></blockquote>  <blockquote><p><b class="note">Note</b>:        May not be used on file pointers returned by    <a href="function.fopen.html" class="function">fopen()</a> if they use the &quot;http://&quot; or &quot;ftp://&quot;    formats. <b>fseek()</b> gives also undefined results for    append-only streams (opened with &quot;a&quot; flag).   <br />  </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.ftell.html" class="function" rel="rdfs-seeAlso">ftell()</a></li>    <li class="member"><a href="function.rewind.html" class="function" rel="rdfs-seeAlso">rewind()</a></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.fscanf.html">fscanf</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.fstat.html">fstat</a></div> <div class="up"><a href="ref.filesystem.html">Filesystem 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 + -