删除字符串的3个第一个字符

I have this code that shows all the directories in the previous page.

$dirs = array_filter(glob('../*'), 'is_dir');

foreach ($dirs as $nav) {
    echo "<li><a href='$nav'>".$nav."</a></li>";
}

The output is like this:

  • ../Gėlės
  • ../dddd
  • ../images

Is there a function or a way that could be used removing ../ prefix from the output string ?

Thank you.

You'll probably get all kinds of wacky string manipulation answers, so here is the proper tool:

basename — Returns trailing name component of path

Which is exactly what you are doing:

basename($nav)

Also, use GLOB_ONLYDIR flag as the second argument in your glob() call if you only want directories.

Sure, you can use str_replace, but I'd go with AbraCadaver's answer...

$dirs = array_filter(glob('../*'), 'is_dir');
foreach ($dirs as $nav) {
    $nav = str_replace("../", "", $nav);
    echo "<li><a href='$nav'>$nav</a></li>";
}

You can subtract 3 chars from beginnings like this:

echo substr($string, 3);