title: Simplifying a directory string
body: <p>Take the following directory structure:</p>
  
  <ul>
  <li>Parent1
  <ul>
  <li>Child folder
  <ul>
  <li>Child Folder 1</li>
  <li>Child Folder 2</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>The path to Child Folder 2 would be:</p>
  
  <pre><code>Parent/Child folder/Child Folder 2
  </code></pre>
  
  <p>But, another valid path can also be</p>
  
  <pre><code>Parent/Child folder/Child Folder 1/../Child Folder 2
  </code></pre>
  
  <p>Is there a way to "Simplify" the path, or convert a path such as:</p>
  
  <pre><code>Parent/Child folder/Child Folder 1/../Child Folder 2
  </code></pre>
  
  <p>to </p>
  
  <pre><code>Parent/Child folder/Child Folder 2
  </code></pre>
  
  <p>I was trying to find a way to extract the file name from the handle that <code>opendir($directory)</code> gives you, but I haven't found a way to do this yet. I'm also pretty sure there must be some terminology or better wording than "simplify", but I did not know what to search for. "Simplify path" php didn't help much.</p>
  
  <p>Edit:</p>
  
  <p>I've noticed realpath gives me the complete, full path. It does not give you the relative one, as in <code>Parent/Child folder/Child Folder 2</code>, but <code>C:\Path\To\Server\Directory\Parent\Child Folder\Child Folder 2</code>
  That's a bit disappointing, but I can convert it back with some string manipulation.</p>