g3x0

Resolve relative URLs

Dec 18th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.35 KB | None | 0 0
  1. function resolve_rurl($url)
  2. {
  3.     $url = explode("/", $url);
  4.  
  5.     foreach ($url as $key => $part)
  6.     {
  7.         if ($part == '..')
  8.         {
  9.             unset($url[$key]);
  10.             unset($url[$key - 1]);
  11.         }
  12.         else if ($part == '.')
  13.         {
  14.             unset($url[$key]);
  15.         }
  16.     }
  17.  
  18.     return implode("/", $url);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment