Archive_Tar::_pathReduction PHP Method

_pathReduction() public method

./bar" to "/dir/bar", rand emove double slashes.
public _pathReduction ( string $p_dir ) : string
$p_dir string path to reduce
return string reduced path
    function _pathReduction($p_dir)
    {
        $v_result = '';
        // ----- Look for not empty path
        if ($p_dir != '') {
            // ----- Explode path by directory names
            $v_list = explode('/', $p_dir);
            // ----- Study directories from last to first
            for ($i = sizeof($v_list) - 1; $i >= 0; $i--) {
                // ----- Look for current path
                if ($v_list[$i] == ".") {
                    // ----- Ignore this directory
                    // Should be the first $i=0, but no check is done
                } else {
                    if ($v_list[$i] == "..") {
                        // ----- Ignore it and ignore the $i-1
                        $i--;
                    } else {
                        if ($v_list[$i] == '' && $i != sizeof($v_list) - 1 && $i != 0) {
                            // ----- Ignore only the double '//' in path,
                            // but not the first and last /
                        } else {
                            $v_result = $v_list[$i] . ($i != sizeof($v_list) - 1 ? '/' . $v_result : '');
                        }
                    }
                }
            }
        }
        $v_result = strtr($v_result, '\\', '/');
        return $v_result;
    }