note 126354 added to function.realpath

From: Date: Thu, 19 Aug 2021 14:16:41 +0000
Subject: note 126354 added to function.realpath
Groups: php.notes 
Request: Send a blank email to php-notes+get-216810@lists.php.net to get a copy of this message
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 ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 217.100.185.202) ---- Manual Page -- https://php.net/manual/en/function.realpath.php Edit -- https://main.php.net/note/edit/126354 Del: integrated -- https://main.php.net/note/delete/126354/integrated Del: useless -- https://main.php.net/note/delete/126354/useless Del: bad code -- https://main.php.net/note/delete/126354/bad+code Del: spam -- https://main.php.net/note/delete/126354/spam Del: non-english -- https://main.php.net/note/delete/126354/non-english Del: in docs -- https://main.php.net/note/delete/126354/in+docs Del: other reasons-- https://main.php.net/note/delete/126354 Reject -- https://main.php.net/note/reject/126354 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#216810) next »