note 15941 added to function.realpath
| From: | php-general at lists dot php dot net | Date: | Tue, 09 Oct 2001 18:32:56 +0000 |
| Subject: | note 15941 added to function.realpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-18726@lists.php.net to get a copy of this message | ||
little extension to handle a path like
".//aa/bb//////cc.gif" or an empty path "" for the realpath() function from
lawrence@shanghaiguide.com
function realPath($path) {
$path = ereg_replace('/+', '/', $path);
$patharray = explode('/', $path);
$path = '';
$count = count($patharray); //We have multiple count($patharray) so a minor bit faster.
for ($i=0; $i<$count; $i++) {
if ( $patharray[$i] == '.' || $patharray[$i]== '..' || ( (($i+1) <
$count) && ($patharray[$i+1]== '..')) ) {
//If the current pos is a . ignore, if pos+1 == .. ignore, lastly if current = .. ignore.
} else {
$path .= $patharray[$i].'/';
}
}
//Trim trailing slash
if (!empty($path)) $path = substr($path, 0, -1);
return $path;
}
thank you, greetings
bs-team
--
http://www.php.net/manual/en/function.realpath.php
http://master.php.net/manage/user-notes.php?action=edit+15941
http://master.php.net/manage/user-notes.php?action=delete+15941
http://master.php.net/manage/user-notes.php?action=reject+15941