Ai
1 Star 0 Fork 0

平凡亦是收获/数据结构和算法

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test.php 791 Bytes
一键复制 编辑 原始数据 按行查看 历史
liuzeming 提交于 2020-12-17 21:44 +08:00 . 初始化
<?php
function mockChangePath($path)
{
if (strpos($path, '.') === false || strpos($path, '..') === false) {
return rtrim($path, '/');
}
$sub_path_list = explode('/', rtrim($path, '/'));
$sub_path_list = array_map(function ($path) {
return $path == "" ? "/" :$path;
}, $sub_path_list);
$target_path_list = array();
foreach ($sub_path_list as $sub_path_item) {
if ($sub_path_item != "." && $sub_path_item != "..") {
$target_path_list[] = $sub_path_item;
continue;
}
if ($target_path_list == "..") {
$target_path_list = array_slice($target_path_list,0, count($target_path_list)-1);
}
}
return implode('/', $target_path_list);
}
var_dump(mockChangePath('/a/./b/../../c/'));
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lzmcode/data-structure-and-algorithm.git
git@gitee.com:lzmcode/data-structure-and-algorithm.git
lzmcode
data-structure-and-algorithm
数据结构和算法
master

搜索帮助