Created
August 5, 2016 13:45
-
-
Save pingyen/e4ac3a27a9c879540b70d649658e5c80 to your computer and use it in GitHub Desktop.
Convert relative path to absolute path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function absolute($base, $relative) { | |
| $stack = explode('/', $base); | |
| array_pop($stack); | |
| foreach (explode('/', $relative) as $part) { | |
| if ($part === '.') { | |
| continue; | |
| } | |
| if ($part === '..') { | |
| array_pop($stack); | |
| continue; | |
| } | |
| array_push($stack, $part); | |
| } | |
| return implode('/', $stack); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment