mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-27 06:18:56 +00:00
166 lines
4.2 KiB
XML
166 lines
4.2 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- splitted from ./en/functions/dir.xml, last change in rev 1.2 -->
|
|
<refentry xml:id="function.readdir" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>readdir</refname>
|
|
<refpurpose>Read entry from directory handle</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>string</type><type>false</type></type><methodname>readdir</methodname>
|
|
<methodparam choice="opt"><type class="union"><type>resource</type><type>null</type></type><parameter>dir_handle</parameter><initializer>&null;</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Returns the name of the next entry in the directory. The
|
|
entries are returned in the order in which they are stored by
|
|
the filesystem.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>dir_handle</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
The directory handle <type>resource</type> previously opened
|
|
with <function>opendir</function>. If the directory handle is
|
|
not specified, the last link opened by <function>opendir</function>
|
|
is assumed.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Returns the entry name on success&return.falseforfailure;.
|
|
</para>
|
|
&return.falseproblem;
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>8.0.0</entry>
|
|
<entry>
|
|
<parameter>dir_handle</parameter> is now nullable.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>List all entries in a directory</title>
|
|
<para>
|
|
Please note the fashion in which <function>readdir</function>'s
|
|
return value is checked in the examples below. We are explicitly
|
|
testing whether the return value is identical to (equal to and of
|
|
the same type as--see <link linkend="language.operators.comparison">Comparison
|
|
Operators</link> for more information) &false; since otherwise,
|
|
any directory entry whose name evaluates to &false; will stop the
|
|
loop (e.g. a directory named "0").
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
if ($handle = opendir('/path/to/files')) {
|
|
echo "Directory handle: $handle\n";
|
|
echo "Entries:\n";
|
|
|
|
/* This is the correct way to loop over the directory. */
|
|
while (false !== ($entry = readdir($handle))) {
|
|
echo "$entry\n";
|
|
}
|
|
|
|
/* This is the WRONG way to loop over the directory. */
|
|
while ($entry = readdir($handle)) {
|
|
echo "$entry\n";
|
|
}
|
|
|
|
closedir($handle);
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>
|
|
List all entries in the current directory and strip out <literal>.</literal>
|
|
and <literal>..</literal>
|
|
</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
if ($handle = opendir('.')) {
|
|
while (false !== ($entry = readdir($handle))) {
|
|
if ($entry != "." && $entry != "..") {
|
|
echo "$entry\n";
|
|
}
|
|
}
|
|
closedir($handle);
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>is_dir</function></member>
|
|
<member><function>glob</function></member>
|
|
<member><function>opendir</function></member>
|
|
<member><function>scandir</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|