PHP two directory relative path example _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.