note 13886 deleted from function.dirname by sniper
| From: | sniper@php.net | Date: | Mon, 09 Dec 2002 06:03:25 +0000 |
| Subject: | note 13886 deleted from function.dirname by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-40558@lists.php.net to get a copy of this message | ||
For a website I have created, I needed to use the directoryname to define the variable $language.
However, dirname gives a total path (i.e. "/~s751294/att/bla/en"), and not just the lowest
subdir (i.e. "en"). The script below does!
<?
// 1. find filename
$language = $PHP_SELF;
// 2. find dirname
$language = dirname($language);
// 3. dirname might exist of more than 1 subdirs
// if ONE "/" is found: this is the last subdir
// if MORE THAN ONE "/" are found: not the last subdir
$subdir = 1;
while ($subdir) {
if (substr_count($language,"/")>1) {
// not at the bottom yet...
$language = dirname($language);
}
else {
// we are at the bottom!
$language = ereg_replace("/","",$language);
$subdir = 0;
}
}
echo "this is the lowest directory: $language";
?>