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);

posted @ 2015-08-04 17:12  上善若水blog  阅读(206)  评论(0编辑  收藏  举报