Jump to content

[SOLVED] Adding ordered list to a directory contents list.


al3x8730

Recommended Posts

I'm using the simple script:

 

<?php

$handle=opendir("users/");

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

}

closedir($handle);


?>

 

Now I want to add an ordered list to that. Is this possible? I tried adding it in around the $file in the echo, but it just repeats 1., 1., 1., etc...

Try this:

 

<?php
echo "<ol>";
foreach(glob("*.php") as $val){
     $file = basename($file, '.php');
     echo "<li>$file</li>";
}
echo "</ol>";
?>

 

That doesn't work. It just shows the numbers, but now it doesn't show the name of the files.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.