//用php求两个文件的相对路径
function compara_path($path_a, $path_b) {
//切割路径.
$array_a =explode('/', $path_a);
$array_b =explode('/', $path_b);
//从数组中删除最后的文件,剩下的全为文件夹名称.
$file_a =array_pop($array_a); //array_pop() 弹出并返回 array 数组的最后一个单元
$file_b =array_pop($array_b);
//子目录个数.
$a_len =count($array_a);
$b_len =count($array_b);
//循环求出第几个目录不同.
for ( $i =0; $i
if ($array_a[$i] != $array_b[$i] ) {
break;
}
}
//求出相对路径.
$com_path ="";
for ( $j =0; $j
$com_path .='../';
}
for ( $i; $i
$com_path .=$array_b[$i] . '/';
}
$com_path .=$file_b;
return $com_path;
}
$path_a = "a/b/c/d/e/f.php";
$path_b = "a/b/z/x/y.php";
echo compara_path($path_a, $path_b);
摘自:小囧的博客

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
