PHP中是否有内置的方法来解析这样的字符串:“ / path / to /../../ up / something.txt”

问题描述:

所以说我有一个像这样的字符串

So say I have a string like so of a path

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

PHP是否有内置的方法来解析它并提供没有目录ups的URL( ../)?

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

例如

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


realpath($path);

文档