Script for listing the files in a particular directory

I am using the following script for listing the files in a particular directory as a hyperlink list. The files names which i have mentioned must not be displayed, How do i change the code for this?

<?php $directory = ''; foreach (glob($directory . "*.php") as $file) { $parts = pathinfo($file); $name = preg_replace("/-/", " ", $parts['filename']); echo "<li><a href=\"{$file}\">{$name}</a></li>"; } ?>

Just replace {$name} with something like LINK or whatever you want.

[php]echo “

  • <a href=”{$file}">LINK
  • ";[/php]

    No. In a directory, i want to list all the php files and not the index.php

    The files names which i have mentioned must not be displayed,

    Ok, you didnt list any filenames to exclude. Here is a cleaner option.

    [php]$files = array_values(preg_grep(’/^((?!index.php).)$/’, glob(".php")));
    foreach ($files as $filename)
    {
    echo “

  • <a href=”{$filename}">".basename($filename, “.php”)."
  • ";
    }[/php]

    One more option

    [php]<?php
    foreach (glob("*.php") as $filename)
    {
    $filename = str_replace(“index.php”, ‘’, $filename);
    if (!empty($filename))
    {
    echo “

  • <a href=”$filename">" . basename($filename, “.php”) . “
  • ”;
    }
    }
    ?>[/php]
    Sponsor our Newsletter | Privacy Policy | Terms of Service