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

raminr63
NewLounger
Posts: 1
Joined: 03 Jun 2012, 18:18

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

Post by raminr63 »

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:

Code: Select all

<?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:

Code: Select all

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

Code: Select all

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

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How i can remove "./" from first of the name in output d

Post by HansV »

Welcome to Eileen's Lounge!

I hope you'll get a helpful reply, but don't hold your breath. We do have a few web programming experts, but it's not a strong point of this board (we mostly get questions about MS Office and Windows).
Best wishes,
Hans

User avatar
Jezza
5StarLounger
Posts: 847
Joined: 24 Jan 2010, 06:35
Location: A Magic Forest in Deepest, Darkest, Kent

Re: How i can remove "./" from first of the name in output d

Post by Jezza »

Hi raminr63

Could you not use the str_replace function

$str=str_replace('./','',$str);

where $str is your declared string, this will remove all the ./
Jerry
I’ll be more enthusiastic about encouraging thinking outside the box when there’s evidence of any thinking going on inside it

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: How i can remove "./" from first of the name in output d

Post by agibsonsw »

I'm guessing this would work, just before returning from the function:

Code: Select all

$retval[0]['name'] = str_replace('./','',$retval[0]['name'],1);
return $retval;
but I'm revising PHP at the moment so I may be wrong :smile:
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.