private static function getRelativePath($from, $to)
    {
        $from = explode('/', $from);
        $to = explode('/', $to);
        $relPath = $to;

        foreach ($from as $depth => $dir) {
            // find first non-matching dir
            if (isset($to[$depth]) && $dir === $to[$depth]) {
                // ignore this directory
                array_shift($relPath);
            } else {
                // get number of remaining dirs to $from
                $remaining = count($from) - $depth;
                if ($remaining > 1) {
                    // add traversals up to first matching dir
                    $padLength = (count($relPath) + $remaining - 1) * -1;
                    $relPath = array_pad($relPath, $padLength, '..');
                    break;
                } else {
                    $relPath[0] = './'.$relPath[0];
                }
            }
        }

        return implode('/', $relPath);
    }
private static function getRelativePath($from, $to)
    {
        $from = explode('/', $from);
        $to = explode('/', $to);
        $relPath = $to;

        foreach ($from as $depth => $dir) {
            // find first non-matching dir
            if (isset($to[$depth]) && $dir === $to[$depth]) {
                // ignore this directory
                array_shift($relPath);
            } else {
                // get number of remaining dirs to $from
                $remaining = count($from) - $depth;
                if ($remaining > 1) {
                    // add traversals up to first matching dir
                    $padLength = (count($relPath) + $remaining - 1) * -1;
                    $relPath = array_pad($relPath, $padLength, '..');
                    break;
                } else {
                    $relPath[0] = './'.$relPath[0];
                }
            }
        }

        return implode('/', $relPath);
    }
private static function getRelativePath ( $ from , $ to ) { $ from = explode ( '/' , $ from ) ; $ to = explode ( '/' , $ to ) ; $ relPath = $ to ; foreach ( $ from as $ depth => $ dir ) { // find first non-matching dir if ( isset ( $ to [ $ depth ] ) && $ dir === $ to [ $ depth ] ) { // ignore this directory array_shift ( $ relPath ) ; } else { // get number of remaining dirs to $from $ remaining = count ( $ from ) - $ depth ; if ( $ remaining > 1 ) { // add traversals up to first matching dir $ padLength = ( count ( $ relPath ) + $ remaining - 1 ) * - 1 ; $ relPath = array_pad ( $ relPath , $ padLength , '..' ) ; break ; } else { $ relPath [ 0 ] = './' . $ relPath [ 0 ] ; } } } return implode ( '/' , $ relPath ) ; }
Returns a relative path based on 2 absolute paths.

@param string $from
@param string $to

@return string
Returns a relative path based on 2 absolute paths .