note 82002 modified in function.dirname by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 19:00:02 +0000 |
| Subject: | note 82002 modified in function.dirname by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142252@lists.php.net to get a copy of this message | ||
Inside of script.php I needed to know the name of the containing directory. For example, if my
script was in '/var/www/htdocs/website/somedir/script.php' i needed to know
'somedir' in a unified way.
The solution is:
<?php
$containing_dir = basename(dirname(__FILE__));
?>
--was--
Inside of script.php I needed to know the name of the containing directory. For example, if my
script was in '/var/www/htdocs/website/somedir/script.php' i needed to know
'somedir' in a unified way.
The solution is:
<?php
$containing_dir = basename(dirname(__FILE__));
?>
Previously I had something very ugly, like this:
<?php
// exploding path into array
$path_arr = explode(DIRECTORY_SEPARATOR, dirname(__FILE__));
// the last entry
$containing_dir = $path_arr[count($path_arr)-1];
?>
http://php.net/manual/en/function.dirname.php