Skip to content

Instantly share code, notes, and snippets.

@mkeneqa
Created January 31, 2020 18:26
Show Gist options
  • Save mkeneqa/35e7db0a04fb63f36f70646431fa3f1a to your computer and use it in GitHub Desktop.
Save mkeneqa/35e7db0a04fb63f36f70646431fa3f1a to your computer and use it in GitHub Desktop.
Symfony PHP, function to get Project Root Directory
<?php
public static function GetProjectRootDir()
{
$dirFullPath = __DIR__;
//PRE: $dirs = /app/public/src/Helpers
$dirs = explode('/',$dirFullPath);
array_pop($dirs); //remove last element in array ('Helpers')
array_pop($dirs); //remove the next last element from array ('src')
//POST: $dirs = /app/public
return implode('/',$dirs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment