#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    133
    Rep Power
    15

    deleting characters in a variable until you reach a "/" character?


    im making an ftp/file manager, i have a variable, ($dir), and lets say $dir consists of "./forums.tech-devil.co.uk/lang", but i want to go up one folder to "./forums.tech-devil.co.uk/", so obviously i want to delete the "lang" from the varable. so i realy just want to delete characters until i get to a "/". how can i do this?
    Last edited by benthekiller; November 11th, 2003 at 03:55 AM.
    benthekiller - http://www.tech-devil.co.uk - webmaster
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    133
    Rep Power
    15
    maybe i could use an explode function and somehow get it to delete the last string that comes out?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    133
    Rep Power
    15
    yes yes yes! i got it to work!

    right, so explaining...

    now, there the $dir variable. now it consists of ./forums.tech-devil.co.uk/, i simply told it to explode into a variable called $path_exploded. the i have a while loop to cycle through the array, every time it goes plus one on an int, that int is used in the array, it checks if the $path_exploded array has that bit of the array set, when it doesnt it has gone past the end, so, it goes minus one, then deletes that bit of the array, then implodes. well enough of my crazy banter, here:

    PHP Code:
                            $path_explode $dir;
                            
    $array_no = -1;

                            
    $path_exploded explode("/",$path_explode);

                            
    $go_up_true_var 1;

                            while(
    $go_up_true_var) {
                                ++
    $array_no;
                                if(!empty(
    $path_exploded[$array_no])) {
                                } else {
                                    --
    $array_no;
                                    unset(
    $path_exploded[$array_no]);
                                    
    $go_up_true_var 0;
                                }
                            }
                            
    $show_path implode("/"$path_exploded);
                            print 
    "<tr><td width=65%><a href=file.php?dir=$show_path
    i am supreeeeeeeeeeeeeeme!!!
    Last edited by benthekiller; November 11th, 2003 at 06:29 AM.
    benthekiller - http://www.tech-devil.co.uk - webmaster
  6. #4
  7. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,800
    Rep Power
    1103
    Try this for a possible quicker solution:
    PHP Code:
    $parent dirname($dir); 
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    133
    Rep Power
    15
    but... but... but...

    i suck... i spent most of today trying to do that when two lines of code woulda done it... spose ill print out the entire function list from php.net.

    thanks for telling me tho, save meself some webspace

IMN logo majestic logo threadwatch logo seochat tools logo