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