note 65211 deleted from function.strstr by bjori
| From: | bjori@php.net | Date: | Thu, 27 Apr 2006 00:23:38 +0000 |
| Subject: | note 65211 deleted from function.strstr by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109803@lists.php.net to get a copy of this message | ||
Note Submitter: thejasondean at yahoo dot com
Reason: bad code
----
Also in response to:
john :: beech :: at :: mkv25 :: dot :: net
Trying to use your function to trim the last directory from a path
i found out that it doesn't work if a directory has the same name as the subdirectory
for example
<?
function backstr($haystack, $needle) {
return substr($haystack, 0, strlen($haystack) - strlen(strstr($haystack,$needle)));
}
echo backstr('/var/www/site/test/test','/test');
// returns "/var/www/site"
// instead of "/var/www/site/test"
?>
My version for solving this 'special' problem :
<?
function back_dir($path){
$go1 = rtrim ($path , '/');
$back_dir = substr ($go1,0,strlen($go1) - strlen(strrchr($go1 , '/')));
return $back_dir . "/";
}
?>