|
Posted by rf on 06/22/07 12:01
"Neredbojias" <neredbojias@gmail.com> wrote in message
news:Xns9956C5BC4E732nanopandaneredbojias@198.186.190.161...
> On Thu, 21 Jun 2007 14:30:49 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
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. May do that
some day. Then again I now my create menus directly from the database and
the routines that access that database know *exactly* what "page" they are
in and they know *precicely* how to write the HTML that will, in due couse,
be selected by the appropriate CSS rules.
> This part I get: ternary (sp?) conditionals, not much different than my
> example.
True. Just a different programmers coding expression of the "algorithm".
>> Next stage is to wrap it up in a nice pretty function.
>
> Sure. I can't wait to have at it...
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 :-)
--
Richard.
Navigation:
[Reply to this message]
|