码迷,mamicode.com
首页 > Web开发 > 详细

php计算两个文件夹的相对路径

时间:2015-06-02 23:25:47      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

<?php 
include ‘../../c/e/one.php‘;
echo "\n";
echo ‘this is two‘;
echo "\n";

$a = "/a/b/c/d/e.php";
$b = "/a/b/12/34/c.php";
$cnta = strlen($a); $cntb = strlen($b); $cnt = max($cnta,$cntb); echo $cnt,"\n"; for($i=1;$i<$cnt;$i++){ $str_a = substr($a,0,$i); $str_b = substr($b,0,$i); if($str_a == $str_b){ $base = $str_a; }else{ break; } } echo $base,"\n"; $start = strlen($base); $a_arr = explode(‘/‘,substr($a,$start)); $a_c_cnt = count($a_arr)-1; $path = ‘‘; for($i=0;$i<$a_c_cnt;$i++){ $path .= "../"; } $path .= substr($a,$start); echo $path,"\n"; $b_arr = explode(‘/‘,substr($b,$start)); $b_c_cnt = count($b_arr)-1; $path = ‘‘; for($i=0;$i<$b_c_cnt;$i++){ $path .= "../"; } $path .= substr($b,$start); echo $path,"\n";

 

php计算两个文件夹的相对路径

标签:

原文地址:http://www.cnblogs.com/wtb123456/p/4547985.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!