note 82002 added to function.dirname
| From: | ts at dev dot websafe dot pl | Date: | Sun, 23 Mar 2008 23:55:06 +0000 |
| Subject: | note 82002 added to function.dirname | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137448@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__));
?>
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];
?>
----
Server IP: 82.177.164.100
Probable Submitter: 79.189.151.26
----
Manual Page -- http://www.php.net/manual/en/function.dirname.php
Edit -- https://master.php.net/note/edit/82002
Del: integrated -- https://master.php.net/note/delete/82002/integrated
Del: useless -- https://master.php.net/note/delete/82002/useless
Del: bad code -- https://master.php.net/note/delete/82002/bad+code
Del: spam -- https://master.php.net/note/delete/82002/spam
Del: non-english -- https://master.php.net/note/delete/82002/non-english
Del: in docs -- https://master.php.net/note/delete/82002/in+docs
Del: other reasons-- https://master.php.net/note/delete/82002
Reject -- https://master.php.net/note/reject/82002
Search -- https://master.php.net/manage/user-notes.php