2019-04-08 23:22:26 +08:00

119 lines
5.5 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>返回一个 Directory 类实例</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.dir" class="refentry">
<div class="refnamediv">
<h1 class="refname">dir</h1>
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">dir</span> &mdash; <span class="dc-title">返回一个 Directory 类实例</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.dir-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>dir</strong></span>
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$directory</code></span>
[, <span class="methodparam"><span class="type">resource</span> <code class="parameter">$context</code></span>
] ) : <span class="type"><a href="class.directory.html" class="type Directory">Directory</a></span></div>
<p class="para rdfs-comment">
以面向对象的方式访问目录。打开
<code class="parameter">directory</code> 参数指定的目录。
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.dir-parameters">
<h3 class="title">参数</h3>
<dl>
<dt>
<code class="parameter">directory</code></dt>
<dd>
<p class="para">
被打开的目录
</p>
</dd>
<dt>
<code class="parameter">context</code></dt>
<dd>
<p class="para">
<blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">在 PHP 5.0.0
中增加了对上下文Context的支持。有关<em>上下文Context</em>的说明参见
<a href="book.stream.html" class="xref">Streams</a></span></p></blockquote>
</p>
</dd>
</dl>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.dir-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
成功的话,返回一个 <a href="class.directory.html" class="classname">Directory</a> 类实例, 参数错误的情况下返回 <strong><code>NULL</code></strong>
其它错误情况返回 <strong><code>FALSE</code></strong>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.dir-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-2749">
<p><strong>Example #1 <span class="function"><strong>dir()</strong></span> 示例</strong></p>
<div class="example-contents"><p>
请特别注意下面示例中 <span class="function"><a href="directory.read.html" class="function">Directory::read()</a></span> 函数返回值的判断方式。
我们严格测试(值相等,并且类型相同,请参考 <a href="language.operators.comparison.html" class="link">
比较运算符</a> )返回值等于 <strong><code>FALSE</code></strong> ,因为有些情况下,目录名可能&quot;等于&quot; <strong><code>FALSE</code></strong> ,导致
跳出循环。
</p></div>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$d&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dir</span><span style="color: #007700">(</span><span style="color: #DD0000">"/etc/php5"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"Handle:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$d</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">handle&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">"Path:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$d</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">path&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />while&nbsp;(</span><span style="color: #0000BB">false&nbsp;</span><span style="color: #007700">!==&nbsp;(</span><span style="color: #0000BB">$entry&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$d</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">read</span><span style="color: #007700">()))&nbsp;{<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$entry</span><span style="color: #007700">.</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">$d</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">close</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程的输出类似于:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
Handle: Resource id #2
Path: /etc/php5
.
..
apache
cgi
cli
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 notes" id="refsect1-function.dir-notes">
<h3 class="title">注释</h3>
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
目录条目返回的顺序依赖于系统。
</p>
</p></blockquote>
</div>
</div></div></div></body></html>