|
Posted by Neredbojias on 06/22/07 20:25
On Fri, 22 Jun 2007 12:01:24 GMT rf scribed:
>>> $page =
>>> array_shift(explode('.',array_pop(explode('/',$_SERVER['PHP_SELF'])))
>>> );
>>
>> Uh, who do you think I am, -Einstein?\
>> I'd take it kindly if you'd please explain the above in detail so my
>> headache would go away and I could get back to watching those reruns
>> of "The Three Stooges" I enjoy so much...
>
> Er, N, it's all in the RTFM.
>
> Start from the inside out...
>
> $_SERVER['PHP_SELF'] contains the path of the current file, from the
> web root IIRC, something like
> /folder/folder/file.ext
>
> _explode_ this into an array, delimited by /
>
> folder,
> folder,
> file.ext
>
> _array-pop_ the *last* element in the array
>
> file.ext
>
> explode this on .
>
> file,
> ext
>
> _array_shift_ the *first* entry out of this array
>
> file
I think my troubles were that I just couldn't intuitively get a handle on
$_SERVER['PHP_SELF'] because the FM didn't give any usage examples (which
I could find), and I'd never even heard of "explode" before. Your
explanation clarifies it beautifully although excessive nesting still
makes me a little bird-brained. 'Tis, indeed, a clever sequence of
functions to derive the active client page filename.
> On looking at the above (written the odd several years ago) I admit
> the whole thing should now be shortened into a preg_match() or two.
I've used that in the past for browser-sniffing. Worked fine if one was
careful enough in setting the _whole_ thing up.
> (snip)
> echo "<ul>\r\n";
> menuitem('page1','Page 1');
> menuitem('page2','Page 2');
> echo "</ul>\r\n";
>
> The expression of function menuitem($page,$text) is up to you :-)
I notice you use \r\n where I typically use just \n (which seems to
suffice.) Do you think it makes any difference?
Thanks for the fine explanation.
--
Neredbojias
He who laughs last sounds like an idiot.
[Back to original message]
|