Home > Backend Development > PHP Tutorial > 使用PHP求两个文件的相对路径_PHP

使用PHP求两个文件的相对路径_PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 12:06:19
Original
786 people have browsed it
复制代码 代码如下:
function compare($ph1,$ph2){
    $ret = '';
    $_f1Arr = explode("/",$ph1);
    $_f2Arr = explode("/",$ph2);

    $f1 = array_pop($_f1Arr);
    $f2 = array_pop($_f2Arr);
    for($i=0;$i        if($_f1Arr[$i] !== $_f2Arr[$i])
            break;
    }
    for($j= $i-1;$j       $ret .= "../";
    }

    for($i-1;$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的相对路径。。。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template