php 计算两个文件之间的相对路径方法

$path1="/test/a1/a2/dd/a1.php";
$path2="/test/b1/b1.php";
function getRelationPath($path1,$path2){
$arr1=explode('/',$path1);
$arr2=explode('/',$path2);
$intersection=array_intersect_assoc($arr1, $arr2);

$douhao=array_fill(0, count($arr1)-count($intersection)-1, "..");
$dier=array_slice($arr1, count($intersection));
$tmp=array_merge($douhao,$dier);
$relativePath=implode("/", $tmp);
return $relativePath;
}
getRelationPath($path1,$path2);

原文地址:https://www.cnblogs.com/w84036937/p/4702550.html