[thelist] Getting path minus document root using PHP
kasimir-k
kasimir.k.lists at gmail.com
Thu Dec 13 15:30:30 CST 2007
Stephen Rider scribeva in 13/12/2007 19:34:
> 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.
how about just
$newstring = preg_replace(
'%^/sites/mysite\.com/public_html%',
'',
$string);
?
.k
More information about the thelist
mailing list