title: Resolve a relative path in a URL with PHP
body: <p>Example 1: <code>domain.com/dir_1/dir_2/dir_3/./../../../</code><br>Should resolve naturally in the browser into = <code>domain.com/</code></p>
  
  <p>Example 2: <code>domain.com/dir_1/dir_2/dir_3/./../../../test/././../new_dir/</code><br>
  Should resolve into <code>domain.com/new_dir/</code></p>
  
  <p>Example 3: <code>domain.com/dir_1/dir_2/dir_3/./../../../test/dir4/../final</code><br>
  Should resolve into <code>domain.com/test/final</code></p>
  
  <p>How can I iterate through the string to do this? I feel like the <code>for()</code> loop would get confused at this point.</p>
  
  <p>The answers provided in <a href="https://stackoverflow.com/questions/4444475/transfrom-relative-path-into-absolute-url-using-php">Transform relative path into absolute URL using PHP</a> and <a href="https://stackoverflow.com/questions/1243418/php-how-to-resolve-a-relative-url">PHP: How to resolve a relative url</a> don't work for me in this case. I shouldn't need a reference point (base), since the objective to clean up what I already have.</p>
  
  <p>This is not a duplicate of <a href="https://stackoverflow.com/questions/36577020/php-failed-to-open-stream-no-such-file-or-directory">PHP - Failed to open stream : No such file or directory</a></p>