Page 1 of 1

Get just parent folder name

Posted: Thu Feb 21, 2008 5:16 pm
by arpowers
Hey Guys!~

I have a question:

I have a directory structure like this:
http://www.root.com/application/script.php

I need to figure out a way to get just the name of the parent folder (not the entire path) of a script. (in above, A quick function that returnd just 'application' would be great!)

This will allow me to define this:
define('CURRENT_APP', need this code...);

this will allow me to dynamically determine which application I am in and will help me redact the code.

What is the best way to do this?

I am familiar with all the functions that return the entire directory path you are in...

THANKS:D
ANDREW

Re: Get just parent folder name

Posted: Thu Feb 21, 2008 5:38 pm
by Christopher
Something like:

Code: Select all

array_pop(explode('/', dirname($_SERVER['SCRIPT_PATH'])))
I don't recall if those are all the right function names.

Re: Get just parent folder name

Posted: Thu Feb 21, 2008 5:49 pm
by alex.barylski

Code: Select all

 
 
$path = 'this/is/an/example/file.dat';
 
$parent = basename(dirname($path));
 
echo $parent; // Result: example
 
 

Re: Get just parent folder name

Posted: Thu Feb 21, 2008 5:53 pm
by arpowers
Good answer arbor ! 5 gold stars...

I didn't think about using explode and array_pop.. pretty simple:)

thanks for your help, It seems like you are always showing me the way.

anybody else has a solution please post it...

Ap

Re: Get just parent folder name

Posted: Thu Feb 21, 2008 6:02 pm
by arpowers
thanks Hockey.. even better:)