Reputation: 4359
Is there a way to convert a path that looks like ../../../
into path/path/path
, I want to make a search class but got to thinking that anyone could pass in the ../
format instead of path/
and return a list of the files that are found.
I started to approach this by using preg_replace()
to find and replace everything up until it matches the $_SERVER['DOCUMENT_ROOT']
in the path being passed. But the only solves the path/path/path
problem.
How would I approach the ../../../
problem?
Upvotes: 0
Views: 105
Reputation: 784918
Not very clear about the ask but probably this will work for you:
$path = '../../..';
$path = str_replace(realpath($path) . '/', '', getcwd());
Upvotes: 0