PHP Gets the file relative path method,
This article explains how PHP obtains file-relative paths. Share to everyone for your reference. The implementation method is as follows:
<?php$a = '/a/b/c/d/e.php '; $b = '/a/b/12/34/c.php ';//. /.. /12/34/c.phpecho Getrelativelypath ($a, $b);//for $b relative path function Getrelativelypath ($a, $b) {$a =explode ('/', $a) relative to $ A $b =explode ('/', $b), Var_dump ($a),//print_r ($b), $c =array_values (Array_diff ($a, $b)), $d =array_values (Array_diff ($b, $ a);//Var_dump ($c);//var_dump ($d); Array_pop ($c); foreach ($c as & $v) {$v = ' ... ';} Var_dump ($c); Var_dump ($d); $arr =array_merge ($c, $d); Var_dump ($arr); $str =implode ("/", $arr); echo $str;}
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/960707.html www.bkjia.com true http://www.bkjia.com/PHPjc/960707.html techarticle php Gets the file relative path method, this article describes the PHP obtains the file relative path the method. Share to everyone for your reference. The implementation method is as follows: php$a = '/a/b/c/d/e ...