Copy code The code is as follows:
function relativePath($aPath, $bPath) {
Split the string
$bArr = explode('/', $bPath);
$aDiffToB = array_diff_assoc($aArr, $bArr); //array_diff_assoc() is used to get the difference between array A and array B For the difference set of elements, if both Key and Value are different, they are regarded as different elements. Here, the elements in the A array that are different from the B array are returned. PATH = '';
for ($ i = 0; $ i & lt; $ Count -1; $ i ++) {
$ PATH. = '../';
🎜>
$path .= implode('/', $aDiffToB); // implode() is used to connect the array elements using the specified string, here returns the string after connecting the array elements with '/'
return $path;
}
echo relativePath('/a/b/c/d/a.php', '/a/b/1/2/b.php');
/d/a.php
http://www.bkjia.com/PHPjc/327622.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/327622.html
TechArticle
Copy the code code as follows: html body ?php function relativePath($aPath, $bPath) { $aArr = explode( '/', $aPath); //explode function is used to split the string and return the split array. Here...