How i can remove "./" from first of the name in output data!!

Hi

in my php out put i get this data:

./dir.php 9e72b711c24294c992824fbe9014f815 124 ./echo.php 51324b9fc549f4b06148e4ff7674518e 239 ./New Text Document.txt d41d8cd98f00b204e9800998ecf8427e 0 ./update.php 90d1bd336fd6604a9bff164099349766 910

i want to remove “./” form the first of file names in output data.

what can i do?!

my php code:


<?PHP
require_once "./dir.php";
require_once "./echo.php";
  function getFileList($dir)
  {
    // array to hold return value
    $retval = array();
    // add trailing slash if missing
  //  if(substr($dir, -1) != "/") $dir .= "/";
    // open pointer to directory and read list of files
    $d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
    while(false !== ($entry = $d->read())) {
      // skip hidden files
      if($entry[0] == ".") continue;
      if(is_dir("$dir$entry")) {
        $retval[] = array(
          "name" => "$dir$entry/",
          "size" => 0,
           "Stream" => md5_file("$dir$entry")
        );
      } elseif(is_readable("$dir$entry")) {
       $retval[] = array(
          "name" => "$dir$entry",
          "size" => filesize("$dir$entry"),
         "Stream" => md5_file("$dir$entry")
        );
      }
   }
    $d->close();
    return $retval;
  }
?>


update.php:

and echo.php:



<?PHP
  // output file list as HTML table
  foreach($dirlist as $file) {
    echo "<tr>
";
    echo "<td>{$file['name']}</td>
";
    echo "<td>{$file['Stream']}</td>
";
    echo "<td>{$file['size']}</td>
";
  }
  echo "
";
?>


and dir.php:



<?PHP
  // examples for scanning the current directory
  $dirlist = getFileList(".");
  $dirlist = getFileList("./");
?>


Thank you

Look at the explode function.

For a one-off, I’d probably use a regex:


function stripit( $str ) {
return preg_replace( '#^[.]/#', '', $str );
}


While the previous answers will work, basename() is actually what you want.