If my URL is http://www.server.com/myapp/stuff/to/see and my directory structure on disk is htdocs/myapp/*, how can I extract the /myapp
$_SERVER['DOCUMENT_ROOT'] will give you the path to htdocs, then you can go from there
EDIT
$_SERVER['REQUEST_URI'] will always give you /myapp/stuff/to/see from your sample url above, regardless of the files location on disk or from which file it is invoked.
so it only a matter of explodeing, array_shifting, and implodeing.
btw, from your directory structure, it looks like you're using a framework. some frameworks have a URI/URL library that you can find useful (at least CodeIgniter has, not 100% sure with other frameworks)