Skip to content

Commit

Permalink
求两个文件的相对路径
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexchent committed Jul 4, 2021
1 parent ecc94f9 commit 20d8bc9
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 13 deletions.
12 changes: 0 additions & 12 deletions cli/clifile.php

This file was deleted.

1 change: 0 additions & 1 deletion cli/publish.php

This file was deleted.

1 change: 1 addition & 0 deletions laboratory/get_relative_path.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php/** * 求a相对于b的路径 * * @param $a * @param $b * @return string */function getRelativePath($a, $b){ $path = ''; $arr = explode('/', $a); $brr = explode('/', $b); //获取两个数组的交集,键值一起比对 $same = array_intersect_assoc($arr, $brr); //获取b相对于a的不同部分 $dir = array_diff_assoc($brr, $same); for($i = 1; $i < count($dir); $i++) { $path .='../'; } $path .= str_replace(implode('/',$same).'/','', $a); return $path;}$a = "/x/y/m/a.txt";$b = "/x/y/n/b.txt";echo getRelativePath($a,$b);
Expand Down

0 comments on commit 20d8bc9

Please sign in to comment.