[thelist] Getting path minus document root using PHP

David Menzel DavidM at circlebroach.net
Thu Dec 13 13:54:00 CST 2007

Looks like your after $_SERVER['PHP_SELF']

There is a list of the pre-defined values here:


Stephen Rider wrote:
> Probably easy for a PHP wiz.  I can kludge it out, but I _know_ there  
> has to be a simpler answer than mine.....
> I have a string that contains the server path of a file within the  
> site document directory.  I want to extract that string _minus_ the  
> document root path, which makes up the beginning of it.
> Can someone tell me the best way to do this with PHP?
> Example:
> $string = "/sites/mysite.com/public_html/subdirectory/myfile.php"
> I want:
> $newstring = "/subdirectory/myfile.php"
> I could just do a search/replace, but I want to watch out for the  
> (unlikely) possibility that the root path could also exist within a  
> later part of $string.  In other words, we must check that the piece  
> removed is always the _beginning_ of $string.
> Thanks in Advance.
> Stephen

More information about the thelist mailing list