方法一:
/**
* 计算$path2相对于$path1的路径
*
* @param string $path1
* @param string $path2
* @author 陌路烟云 <moluyanyun@163.com>
* @since 2014-06-13
* @return string
*/
function get_relative_path($path1='', $path2='')
{
$arr_path1 = explode('/', $path1);
$arr_path2 = explode('/', $path2);
$intersection = array_intersect($arr_path1, $arr_path2);
$pathinfo = str_repeat('../', count($arr_path1)-count($intersection)-1);
for( $i = count($intersection); $i <= count($arr_path2)-2; $i++ )
{
$pathinfo.= $arr_path2[$i].'/';
}
return $pathinfo;
}
$a = '/a/b/b/d/e/f.php';
$b = '/a/b/b/12/34/c.php';
echo get_relative_path($a,$b);