php求两个文件相对路径_PHP教程

WBOY
Freigeben: 2016-07-13 17:46:21
Original
840 Leute haben es durchsucht

//用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);

摘自:小囧的博客

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478585.htmlTechArticle?php //用php求两个文件的相对路径 function compara_path($path_a, $path_b) { //切割路径. $array_a =explode(/, $path_a); $array_b =explode(/, $path_b); //从数组中删除...
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!