On Thu, 2002-02-14 at 07:32, Erik Price wrote:
> Hm... I tried quite a few variations on this.  I can't seem to get any 
> displayable value out of this function.
> 
> function get_current_page_name()
> {
> $current_page_name = explode("/", $_SERVER['PHP_SELF']);
> $current_page_name = $current_page_name[-1];
> return $current_page_name ;
> }
> 
> $errorcode = get_current_page_name();
> echo $errorcode;
> 
> Nothing.
> 
> The only thing that works is $errorcode = 
> basename($_SERVER['PHP_SELF']), but that's not the point -- I still 
> don't understand why the function above doesn't return anything.  In 
> this case, I'm positive that I've specified the last element of the 
> array.  (Haven't I?)

Hi Erik. :)

No, you've asked for the element of $current_page_name which has the key
-1. To get the last element, probably the easiest thing to do is:

    return $current_page_name[count($current_page_name) - 1];

However, a somewhat less expensive way to do it:

    $path = $_SERVER['PHP_SELF'];
    return substr($path, strrpos($path, '/') + 1);

(No array overhead.)


Cheers (man, it's sunny in Vancouver! Weird...),

Torben
 
> Erik
> 
> On Wednesday, February 13, 2002, at 05:03  PM, Darren Gamble wrote:
> 
> > I think what you're trying to do is return one particular element out 
> > of the
> > array.  If that's the case, just use something like:
> >
> > return $current_page_name[-1]
> >
> > to return the last element in the array.

I do not know where this came from, but it just ain't so.


-- 
 Torben Wilson <[EMAIL PROTECTED]>
 http://www.thebuttlesschaps.com
 http://www.hybrid17.com
 http://www.inflatableeye.com
 +1.604.709.0506


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to