Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online

readdir function syntax tag tutorial 2013 Donate at flattr Flattr this





Alert! Connect with 10,000 Chating Online. Join Now

Php readdir () function

Write your php code

 
<?php ?>

Php Result


Your code below



(PHP 3, PHP 4 , PHP 5)

readdir -- Read entry from directory handle

Syntax

string readdir ( resource dir_handle )

Returns the filename of the next file from the directory. The filenames are returned in the order in which they are stored by the filesystem.

Please note the fashion in which readdir()'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 Comparison Operators for more information) FALSE since otherwise, any directory entry whose name evaluates to FALSE will stop the loop (e.g. a directory named "0").

Example 1. List all files in a directory

<?php
// Note that !== did not exist until 4.0.0-RC2

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 WRONG way to loop over the directory. */
    
while ($file = readdir($handle)) {
        echo
"$file\n";
    }

    
closedir($handle);
}
?>

Note that readdir() will return the . and .. entries. If you don't want these, simply strip them out:

Example 2. List all files in the current directory and strip out . and ..

<?php
if ($handle = opendir('.')) {
    while (
false !== ($file = readdir($handle))) {
        if (
$file != "." && $file != "..") {
            echo
"$file\n";
        }
    }
    
closedir($handle);
}
?>

See also is_dir() and glob().

Php readdir Function syntax tag

readdir php code on this is provided for your study purpose, it will guide you to know how create and design a website using php. use it to practice and train your self online



Php readdir syntax tutorial

php tutorial guide and code design are for easy learning and programming. The code practice section provided at the top is for practising of this syntax. Use the code section up to practice your php programming online. Learning php is very easy, all you need is to use the examples on this site and practice them to perfect your skills.


Function index

Variables

Expressions

Operators

Control-Structures

Cookies

Array

Date & Time

Directory function

File

Image

Operators

Form data handling

Mathematics operators

Mail

Php Mysql

Network Functions

Strings

php tutorial guides,functions, classes, code examples and tags for creating simple dynamic site to mysql database driven sites
 
 
Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online