fork(1) download
  1. <?php
  2.  
  3. function calculateRelativePath($a,$b) {
  4. if (empty($a) || empty($b))
  5. return;
  6. $flag = "";
  7. $split1 = explode("/",$a);
  8. $split2 = explode("/",$b);
  9. $diff1 = array_diff_assoc($split1, $split2);
  10. $count = count($diff1 );
  11. for($i=0; $i < $count-1; $i++) {
  12. $flag .= "../";
  13. }
  14. $diff2 = array_diff_assoc($split2, $split1);
  15. return $flag. implode("/",$diff2);
  16. }
  17. $relative = calculateRelativePath("/a/b/c/d/e.php","/a/b/12/34/c.php");
  18. print_r($relative);
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
../../12/34/c.php