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

**URL:** <https://boards.straightdope.com/t/how-i-can-remove-from-first-of-the-name-in-output-data/623957>\
**Category:** Factual Questions\
**Created:** [June 3, 2012, 6:35pm UTC](https://boards.straightdope.com/t/how-i-can-remove-from-first-of-the-name-in-output-data/623957 "2012-06-03T18:35:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![raminr63](https://avatars.discourse-cdn.com/v4/letter/r/dc4da7/32.png) [@raminr63](https://boards.straightdope.com/u/raminr63)\
**Post date:** [June 3, 2012, 6:35pm UTC](https://boards.straightdope.com/t/how-i-can-remove-from-first-of-the-name-in-output-data/623957/1 "2012-06-03T18:35:24Z")

</div>

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:

```auto

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

```auto

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

```auto

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

```

Thank you

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [June 3, 2012, 7:17pm UTC](https://boards.straightdope.com/t/how-i-can-remove-from-first-of-the-name-in-output-data/623957/2 "2012-06-03T19:17:20Z")

</div>

Look at the [explode](http://php.net/manual/en/function.explode.php) function.

---

<div class="post-metadata">

**Author:** ![tellyworth](https://avatars.discourse-cdn.com/v4/letter/t/977dab/32.png) [@tellyworth](https://boards.straightdope.com/u/tellyworth)\
**Post date:** [June 3, 2012, 10:00pm UTC](https://boards.straightdope.com/t/how-i-can-remove-from-first-of-the-name-in-output-data/623957/3 "2012-06-03T22:00:08Z")

</div>

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

```auto

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

```

---

<div class="post-metadata">

**Author:** ![phaemon](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@phaemon](https://boards.straightdope.com/u/phaemon)\
**Post date:** [June 4, 2012, 12:52am UTC](https://boards.straightdope.com/t/how-i-can-remove-from-first-of-the-name-in-output-data/623957/4 "2012-06-04T00:52:37Z")

</div>

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