Skip to content

Instantly share code, notes, and snippets.

@lytedev
Last active August 29, 2015 14:06
Show Gist options
  • Save lytedev/c224d995a19ef034011a to your computer and use it in GitHub Desktop.
Save lytedev/c224d995a19ef034011a to your computer and use it in GitHub Desktop.
Simple PHP "Get Application Root" Function
<?php
function getSiteRoot()
{
$docRoot = str_replace("\\", "/", $_SERVER['DOCUMENT_ROOT']);
$fileDir = str_replace("\\", "/", dirname(__FILE__));
$cut = explode($docRoot, $fileDir);
if (count($cut) > 1) {
return $cut[1];
}
return $fileDir;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment