mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-29 04:52:50 +08:00
153 lines
6.7 KiB
HTML
153 lines
6.7 KiB
HTML
<!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>在文件指针中定位</title>
|
||
</head>
|
||
<body class="docs"><div id="layout">
|
||
<div id="layout-content"><div id="function.fseek" class="refentry">
|
||
<div class="refnamediv">
|
||
<h1 class="refname">fseek</h1>
|
||
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">fseek</span> — <span class="dc-title">在文件指针中定位</span></p>
|
||
|
||
</div>
|
||
|
||
<div class="refsect1 description" id="refsect1-function.fseek-description">
|
||
<h3 class="title">说明</h3>
|
||
<div class="methodsynopsis dc-description">
|
||
<span class="methodname"><strong>fseek</strong></span>
|
||
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$handle</code></span>
|
||
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$offset</code></span>
|
||
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$whence</code><span class="initializer"> = SEEK_SET</span></span>
|
||
] ) : <span class="type">int</span></div>
|
||
|
||
<p class="para rdfs-comment">
|
||
在与
|
||
<code class="parameter">handle</code>
|
||
关联的文件中设定文件指针位置。
|
||
新位置从文件头开始以字节数度量,是以
|
||
<code class="parameter">whence</code>
|
||
指定的位置加上
|
||
<code class="parameter">offset</code>。
|
||
</p>
|
||
<p class="para">
|
||
In general, it is allowed to seek past the end-of-file; if data is then
|
||
written, reads in any unwritten region between the end-of-file and the
|
||
sought position will yield bytes with value 0. However, certain streams
|
||
may not support this behavior, especially when they have an underlying
|
||
fixed size storage.
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 parameters" id="refsect1-function.fseek-parameters">
|
||
<h3 class="title">参数</h3>
|
||
<p class="para">
|
||
<dl>
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">handle</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">文件系统指针,是典型地由
|
||
<span class="function"><a href="fopen.html" class="function">fopen()</a></span> 创建的 <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span>(资源)。</p>
|
||
</dd>
|
||
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">offset</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
偏移量。
|
||
</p>
|
||
<p class="para">
|
||
要移动到文件尾之前的位置,需要给
|
||
<code class="parameter">offset</code> 传递一个负值,并设置 <code class="parameter">whence</code>
|
||
为 <strong><code>SEEK_END</code></strong>。
|
||
</p>
|
||
</dd>
|
||
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">whence</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
<code class="parameter">whence</code> values are:
|
||
<ul class="simplelist">
|
||
<li class="member"><strong><code>SEEK_SET</code></strong> - 设定位置等于 <code class="parameter">offset</code> 字节。</li>
|
||
<li class="member"><strong><code>SEEK_CUR</code></strong> - 设定位置为当前位置加上 <code class="parameter">offset</code>。</li>
|
||
<li class="member"><strong><code>SEEK_END</code></strong> - 设定位置为文件尾加上
|
||
<code class="parameter">offset</code>。</li>
|
||
</ul>
|
||
</p>
|
||
</dd>
|
||
|
||
|
||
</dl>
|
||
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 returnvalues" id="refsect1-function.fseek-returnvalues">
|
||
<h3 class="title">返回值</h3>
|
||
<p class="para">
|
||
成功则返回 0;否则返回 -1。注意移动到 EOF 之后的位置不算错误。
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 examples" id="refsect1-function.fseek-examples">
|
||
<h3 class="title">范例</h3>
|
||
<p class="para">
|
||
<div class="example" id="example-2806">
|
||
<p><strong>Example #1 <span class="function"><strong>fseek()</strong></span> 例子</strong></p>
|
||
<div class="example-contents">
|
||
<div class="phpcode"><pre><span style="color: #000000">
|
||
<span style="color: #0000BB"><?php<br /><br />$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'somefile.txt'</span><span style="color: #007700">, </span><span style="color: #DD0000">'r'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// read some data<br /></span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #0000BB">fgets</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #0000BB">4096</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// move back to the beginning of the file<br />// same as 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">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span>
|
||
</span>
|
||
</pre></div>
|
||
</div>
|
||
|
||
</div>
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 notes" id="refsect1-function.fseek-notes">
|
||
<h3 class="title">注释</h3>
|
||
<blockquote class="note"><p><strong class="note">Note</strong>:
|
||
<p class="para">
|
||
如果使用附加模试(<em>a</em> 或 <em>a+</em>),任何写入文件数据都会被附加上去,而文件的位置将会被忽略,调用 <span class="function"><strong>fseek()</strong></span> 的结果尚未定义。
|
||
</p>
|
||
</p></blockquote>
|
||
<blockquote class="note"><p><strong class="note">Note</strong>:
|
||
<p class="para">
|
||
Not all streams support seeking. For those that do not support seeking,
|
||
forward seeking from the current position is accomplished by reading
|
||
and discarding data; other forms of seeking will fail.
|
||
</p>
|
||
</p></blockquote>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 seealso" id="refsect1-function.fseek-seealso">
|
||
<h3 class="title">参见</h3>
|
||
<p class="para">
|
||
<ul class="simplelist">
|
||
<li class="member"><span class="function"><a href="ftell.html" class="function" rel="rdfs-seeAlso">ftell()</a> - 返回文件指针读/写的位置</span></li>
|
||
<li class="member"><span class="function"><a href="rewind.html" class="function" rel="rdfs-seeAlso">rewind()</a> - 倒回文件指针的位置</span></li>
|
||
</ul>
|
||
</p>
|
||
</div>
|
||
|
||
|
||
</div></div></div></body></html> |