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
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Identifying The Name Of A Folder

    One one site I am using this script to identify the name of the file that executes that script (minus the extension)

    PHP Code:
    preg_replace('/(.+)(\..+?)$/''\\1'basename($_SERVER['PHP_SELF'])) 
    On a new site I want to identify the name of the folder containing the file executs this script, ie. if this code was run from www.mysite.com/folder/file.php at the moment it will return "file" but I would like it to return "folder".

    I am not sure where I got the above script but I am absolutely dumbfounded when it comes to regular expressions! I would really appreciate any help I can get on making this folder identifying script.

    Thanks heaps.
    eTheory - the theory of revolution

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'd go for exploding the variable around a / delimiter and then accessing the array parts

    $path_bits = explode('/',basename($_SERVER['PHP_SELF']);
    $num_bits = count($path_bits);

    $file = $path_bits[($num_bits - 1)];
    $folder = $path_bits[($num_bits - 2)];
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, that's much easier to follow!

    We have to remove the word "basename" but appart from that it works perfectly.

    Thanks a lot
    eTheory - the theory of revolution


  •  

    Posting Permissions

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