[thelist] Getting path minus document root using PHP

Stephen Rider evolt_org at striderweb.com
Thu Dec 13 14:31:56 CST 2007


I thought of that, but this won't necessarily run _from_ the file  
identified in the string.

Isn't there a simple way to say "This string, minus this other string"?

Stephen

On Dec 13, 2007, at 1:54 PM, David Menzel wrote:

> Looks like your after $_SERVER['PHP_SELF']
>
> There is a list of the pre-defined values here:
> http://us.php.net/manual/en/reserved.variables.php
>
> David
>
> 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.



More information about the thelist mailing list