note 126354 deleted from function.realpath by salathe

From: Date: Thu, 19 Aug 2021 14:27:34 +0000
Subject: note 126354 deleted from function.realpath by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-216812@lists.php.net to get a copy of this message
Note Submitter: greaties at ghvernuft dot nl ---- I extended Sven Arduwie's solution a bit since: https://www.php.net/manual/en/forward/../function.realpath.php#84012 results: https:/www.php.net/manual/en/function.realpath.php#84012 (Only one slash between https: and www) <?php function unsymlink($path) { $pathocol = explode('///',$path, 2); // since File:/// used to be a protocol too if(count($pathocol) == 1) {$pathocol = explode('//',$path, 2);} $path = array_pop($pathocol); $protocol = array_shift($pathocol); // https://www.php.net/manual/en/function.realpath.php#84012 $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; } } $absolutes[0] = ($protocol =="" ? "" : $protocol."//").$absolutes[0]; return implode(DIRECTORY_SEPARATOR, $absolutes); } ?> This will result to the correct url: https://www.php.net/manual/en/function.realpath.php#84012

« previous php.notes (#216812) next »