On Thu, 07 Aug 2003 16:09:24 -0700, george wrote:
Hi Jeffrey.
Hmm.
No, this again gives me the originating page, not the folder that it's in,
ie, test.php, rather than [x].
*grin*
do array_pop() twice, then:
<?
$path = preg_replace("/^\/|\/$/", "", $_SERVER['PATH_TRANSLATED']);
$path_array = split("/", $path);
array_pop($path_array);
$page_name = array_pop($path_array);
?>
My questions to you are:
* What does the REQUEST_URI look like?
i.e. is it a directory (ends in a slash) or a file? The original code I
gave works if the URI ends in the *directory* name, not a file name!
* Do you understand the logic of the above code? What is it that I am
doing?
I'll explain in English what each line does. I find that for complex tasks
it is often best to speak out loud the steps or write them down as
sentences -- English sentences, not code sentences. Then convert English
logic to code logic. So, here goes:
1) Get URI; *assume* URI is a directory.
2) See if URI ends in a slash, if so, we want to get rid of it.
3) make a list of all the elements in the URI where the element delimeter
is the slash (/) character.
4) get the last item in the list.
Number 4 is the part that really assumes that the URI is a *directory* and
not a file! If the URI ends in a file name, number 4 shuold read "Take the
second-to-last item in the list"
Good luck!
--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website |
http://www.wse.jhu.edu/newtnotes/