mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
update examples to test result of opendir() before trying to call readdir().
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@77443 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
262c9bfa38
commit
ba0ec0111a
1 changed files with 22 additions and 20 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.37 $ -->
|
||||
<!-- $Revision: 1.38 $ -->
|
||||
<reference id="ref.dir">
|
||||
<title>Directory functions</title>
|
||||
<titleabbrev>Directories</titleabbrev>
|
||||
|
@ -248,21 +248,22 @@ if ($dir = @opendir("/tmp")) {
|
|||
<![CDATA[
|
||||
// Note that !== did not exist until 4.0.0-RC2
|
||||
<?php
|
||||
$handle=opendir('/path/to/files');
|
||||
echo "Directory handle: $handle\n";
|
||||
echo "Files:\n";
|
||||
if ($handle = opendir('/path/to/files')) {
|
||||
echo "Directory handle: $handle\n";
|
||||
echo "Files:\n";
|
||||
|
||||
/* This is the correct way to loop over the directory. */
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
echo "$file\n";
|
||||
/* This is the correct way to loop over the directory. */
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
echo "$file\n";
|
||||
}
|
||||
|
||||
/* This is the WRONG way to loop over the directory. */
|
||||
while ($file = readdir($handle)) {
|
||||
echo "$file\n";
|
||||
}
|
||||
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
/* This is the WRONG way to loop over the directory. */
|
||||
while ($file = readdir($handle)) {
|
||||
echo "$file\n";
|
||||
}
|
||||
|
||||
closedir($handle);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -281,13 +282,14 @@ closedir($handle);
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$handle = opendir('.');
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file != "." && $file != "..") {
|
||||
echo "$file\n";
|
||||
}
|
||||
if ($handle = opendir('.')) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file != "." && $file != "..") {
|
||||
echo "$file\n";
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
closedir($handle);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
Loading…
Reference in a new issue