欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用PHP計(jì)算兩個(gè)路徑的相對(duì)路徑

 更新時(shí)間:2013年06月14日 15:31:19   作者:  
本篇文章是對(duì)用PHP計(jì)算兩個(gè)路徑的相對(duì)路徑進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
復(fù)制代碼 代碼如下:

<html>
     <body>
         <?php
             function relativePath($aPath, $bPath) {
                 $aArr = explode('/', $aPath);    //explode函數(shù)用于切分字符串,返回切分后的數(shù)組,此處用'/'切分字符串
                 $bArr = explode('/', $bPath);
                 $aDiffToB = array_diff_assoc($aArr, $bArr);    //array_diff_assoc()用于獲取A數(shù)組與B數(shù)組之間元素的差集,Key和Value都不相同視為不同元素,此處返回在A數(shù)組中且與B數(shù)組不相同的元素
                 $count = count($aDiffToB);

                 $path = '';
                 for($i = 0; $i < $count - 1; $i++){
                     $path .= '../';
                 }

                 $path .= implode('/', $aDiffToB);    //implode()用于使用指定字符串連接數(shù)組元素,此處返回用'/'連接數(shù)組元素后的字符串

                 return $path;
             }

             echo relativePath('/a/b/c/d/a.php', '/a/b/1/2/b.php');
         ?>
     </body>
 </html>

頁(yè)面輸出
. ./. ./c/d/a.php

相關(guān)文章

最新評(píng)論