PHP中是否有内置的方法来解析这样的字符串:“ / path / to /../../ up / something.txt” [英] Is there an inbuilt way in PHP to parse a string like this: '/path/to/../../up/something.txt'
本文介绍了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);
这篇关于PHP中是否有内置的方法来解析这样的字符串:“ / path / to /../../ up / something.txt”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文