Search code examples
phpdirectory-structure

Is there an inbuilt way in PHP to parse a string like this: '/path/to/../../up/something.txt'


So say I have a string like so of a path

$path = '/path/to/../../up/something.txt';

Is there a way built into PHP to parse it and come up with a URL without the directory ups (../) ?

E.g.

$path = parsePath('/path/to/../../up/something.txt'); // /up/something.txt

Solution

  • realpath($path);
    

    Docs