Jump to content

Recommended Posts

Actually I'm trying to replace something in a directory contents listing.

 

I want to replace 3 file names.

 

And for 1 I'm using this:

<?php

$handle=opendir(".");

while (($file = readdir($handle))!==false) {
echo str_replace( "index.php", "", $file ) . " <br />";

}
closedir($handle);


?>

 

But if I repeat the line: echo str_replace( "index.php", "", $file ) . " <br />"; and just replace it with a different file name It doesn't work because it repeats the other files names.

Why didn't you use the rename() function?

 

I don't want to rename the file, just rename it on that list.

I presume you mean you don't want the index.php file displayed in the generated list. You should do this instead:

<?php

$handle = opendir(".");

$ignore_files = array('.', '..', 'index.php');

while (($file = readdir($handle))!==false)
{
    // do not display files listed in the ignore_files array
    if(!in_array($file, $ignore_files))
    {
        echo $file . '<br />';
    }
}

closedir($handle);

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.