note 111338 deleted from function.realpath by danbrown
| From: | danbrown@php.net | Date: | Tue, 05 Mar 2013 16:10:54 +0000 |
| Subject: | note 111338 deleted from function.realpath by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193924@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
small modification for get_absolute_path posted by previous user, it fails with linux, missing the
first /
function get_absolute_path($path) {
$path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
$parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
$absolutes = array();
foreach ($parts as $part) {
if ('.' == $part) continue;
if ('..' == $part) {
array_pop($absolutes);
} else {
$absolutes[] = $part;
}
}
return
(strtolower(php_uname("s"))=="linux"?"/":"").implode(DIRECTORY_SEPARATOR,
$absolutes);
}