Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: catch subfolder

  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    catch subfolder

    Hi,
    I have been using
    Code:
    $script = strrchr($_SERVER['PHP_SELF'],"/");
    $script = str_replace("/", "", $script);
    to catch the script of the page you're on then execute if/else statements on the outcome. I've hit a slight snag because now I need to get the subfolder that its in and only the subfolder, how do I say grab whats in between the second last "/" and the last "/" ???? confused!

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    PHP Code:
    <?php
    $bits
    =explode('/',$_SERVER['PHP_SELF']);
    echo 
    $bits[(count($bits)-1)];
    ?>
    or is it -2 ?
    Last edited by firepages; 06-25-2007 at 07:24 AM. Reason: typo, slash not dot
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Regular Coder
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post
    nice hehe, I've always found the long way around doing something

    PHP Code:
    $fLoc $_SERVER['PHP_SELF'];
    $fLocExp explode("/"$fLoc);
    $fLocKey array_keys($fLocExp);
    $fLocLastKey end($fLocKey);

    echo 
    "full: " .$fLoc "<br />";
    echo 
    "subdir: " $fLocExp[$fLocLastKey 1] . "<br />"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •