使用PHP求两个文件的相对路径
代码如下:
function compare($ph1,$ph2){ $ret = ''; $_f1Arr = explode("/",$ph1); $_f2Arr = explode("/",$ph2); $f1 = array_pop($_f1Arr); $f2 = array_pop($_f2Arr); for($i=0;$i<count($_f1Arr);$i++){ if($_f1Arr[$i] !== $_f2Arr[$i]) break; } for($j= $i-1;$j<count($_f1Arr);$j++){ $ret .= "../"; } for($i-1;$i<count($_f2Arr);$i++){ $ret .= $_f2Arr[$i].'/'; } return $ret.$f2; } $file1 = "aaa/ddd/ccc/ddd/test/a.js"; $file2 = "aaa/ddd/ccc/ddd/test/b.js"; echo compare($file1,$file2); ?>
B对于A的相对路径。。。
相关推荐
Bonrui编程路 2020-07-18
深井兮兮 2020-07-18
Alisa0 2020-06-14
DBATips 2020-06-07
atb 2020-04-18
taoqidejingling 2020-03-05
小惠 2020-03-03
sunln00 2020-02-20
林大夏 2020-02-16
aihenaichadeyun 2019-12-20
csdnyasin 2019-12-21
福叔 2019-12-09
gaozhlzh 2013-09-11
心动 2019-11-17
lyccsu 2015-05-15
lhxxhl 2019-06-10
snowknow 2019-07-01
lovexiaoqiqi 2019-05-20
Dongxiem 2015-09-08