This article mainly introduces the PHP two directory relative path example (PHP get relative path), the need for friends can refer to the following
For the relative path of two directories, do not limit the path depth code as follows:/** * Output $b relative path relative to $ A ($a) * Unlimited path depth, no optimizations, just implement function */function GetPath ($a, $b) {$aArr = explode ('/ ', dirname ($a)); $BARR = explode ('/', dirname ($b)); $aLen = count ($AARR); $bLen = count ($BARR); $len = Max ($aLen, $bLen); $k = 0; for ($i = 0; $i < $len; $i + +) {if ($k = = 0) {if (Isset ($AARR [$i]) && ($AARR [$i]! = $BARR [$i]) {$d. = '). /'; if (Isset ($BARR [$i])) {$nP [$i] = $BARR [$i];} $k = $k + 1; }} else {if (Isset ($AARR [$i]) {$d. = '). /'; } if (Isset ($BARR [$i])) {$nP [$i] = $BARR [$i];}} } Echo $d. Implode ('/', $nP);}
http://www.bkjia.com/PHPjc/747074.html www.bkjia.com true http://www.bkjia.com/PHPjc/747074.html techarticle This article mainly introduces the PHP two directory relative path example (PHP get relative path), the need for friends can refer to the following two directory relative path, do not limit the path depth code such as ...