title: Get relative path to a parent directory
body: <p>I have a scenario where I want to get a path back to a specific parent directory. Here is an example folder strcuture (<code>[something]</code> is a folder)</p>
  
  <pre><code>index.php
  [components]
      header.php
      footer.php
  [pages]
      somePage.php
      [somePageSubPages]
          someSubPage.php
  </code></pre>
  
  <p>So my content pages look something like this:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
      include('components/header.php');
  ?&gt;
  
  &lt;!-- CONTENT STUFF --&gt;
  
  &lt;?php
      include('components/footer.php');
  ?&gt;
  </code></pre>
  
  <p>This works for the <code>index.php</code> but not for <code>somePage.php</code> and <code>someSubPage.php</code>. What I want to do is create a function that returns the path back to the main directory so I can then add this to the includes and other stuff:</p>
  
  <pre class="lang-php prettyprint-override"><code>$relPath = getPathToRoot($rootDirName);
  include($relPath . 'components/header.php');
  </code></pre>
  
  <p>And the function only would return an empty string or <code>../../</code>.</p>
  
  <p>I thought about using <code>__FILE__</code> and then just count the <code>/</code>-characters between the given $rootDirName and the the string end. However, I would like to ask if this is a reliable way and how this would look in PHP. (I don't realy work that much with PHP...)</p>