[thelist] Getting path minus document root using PHP

Stephen Rider evolt_org at striderweb.com
Thu Dec 13 13:34:26 CST 2007

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?

$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.


More information about the thelist mailing list