I'm still playing with the string-handling method. moving the negation in, and noting that strlen(substr(foo,1)) = strlen(foo)-1 I get so far:
echo substr($_SERVER['PHP_SELF'],1,
-(
strlen(strrchr($_SERVER['PHP_SELF'], "/"))
+
strlen(strrchr(dirname($_SERVER['PHP_SELF']), "/"))
)
);
Not to mention using regexps:
preg_match("!^.(.*?)(/[^/]+){2}$!", $_SERVER['PHP_SELF'], $parent);
echo $parent[1];