Most short hand, efficient way to do this file path construction
<p>So i'm being pretty hacky here but it works (i welcome any other suggestions) - i'm hoping someone can show me a shorter, more compact way to execute the following:</p>

<pre><code>$directories = explode('/',trim(str_replace(trim(basename($_SERVER['PHP_SELF'])),"",trim( $_SERVER['PHP_SELF'] ) ),'/'));
foreach ($directories as $key =&gt; $directory) {$torootlevel .= "../";}

require_once($torootlevel . "config.php");
</code></pre>

<p>The code basically checks where you are in the application and iterates through the directory structure to get the file path to the root of the app. Its the first and only time i use this code as it loads my config.php file which provides me constants for paths that are used further down the code.</p>

<pre><code>...
require_once(DIR_APP . "inc/class.interface.php");
</code></pre>