Hello,

How can I take a string like this:

gallery/folder/subfolder/subsubfolder/

and turn it into this?

gallery/folder/subfolder/

?

(e.g. getting rid of the last folder in the list: the equivalent of <a href="../"> in HTML.

Please help me! My PHP version is still 4.4.2, so I can't use some functions, and I need some way to do this!

Thanks in advance

lupus6x9

    One possibility:

    $path = "gallery/folder/subfolder/subsubfolder/";
    $newpath = basename(rtrim($path, '/')) . '/';
    

    Another possibility:

    $newpath = preg_replace('#[^/]+/?$#', '/', $path);
    

      I used:

      echo basename(rtrim($id, "/")) . "/";

      for the string: gallery/test_gallery_a/subgallery_1 and it returned:

      subgallery_1/ instead of

      gallery/test_gallery_a

      This is the idea I want, but it seems to be giving me the wrong output; I want the other end of the string.

      Part of this is my fault:

      I mean, I want to replace a string in the format of:

      gallery/test_gallery_a/subgallery_1

      with

      gallery/test_gallery_a

      (without trailing slashes in either).

        NogDog;10895796 wrote:

        My bad: use [man]pathname/man instead of [man]basename/man

        pathname() isn't a function.

        EDIT: but [man]dirname[/man] is, and it works! Thank you!

          Eh...one of those "name" functions. That'll teach me to depend on my memory. :rolleyes:

            Write a Reply...