You are here

function Net_URL::resolvePath in Flickr API 5

Resolves //, ../ and ./ from a path and returns the result. Eg:

/foo/bar/../boo.php => /foo/boo.php /foo/bar/../../boo.php => /boo.php /foo/bar/.././/boo.php => /foo/boo.php

This method can also be called statically.

Parameters

string $url URL path to resolve:

Return value

string The result

1 call to Net_URL::resolvePath()
HTTP_Request::sendRequest in phpFlickr/PEAR/HTTP/Request.php
Sends the request

File

phpFlickr/PEAR/Net/URL.php, line 345

Class

Net_URL

Code

function resolvePath($path) {
  $path = explode('/', str_replace('//', '/', $path));
  for ($i = 0; $i < count($path); $i++) {
    if ($path[$i] == '.') {
      unset($path[$i]);
      $path = array_values($path);
      $i--;
    }
    elseif ($path[$i] == '..' and ($i > 1 or $i == 1 and $path[0] != '')) {
      unset($path[$i]);
      unset($path[$i - 1]);
      $path = array_values($path);
      $i -= 2;
    }
    elseif ($path[$i] == '..' and $i == 1 and $path[0] == '') {
      unset($path[$i]);
      $path = array_values($path);
      $i--;
    }
    else {
      continue;
    }
  }
  return implode('/', $path);
}