Create a menu in php. For people who have used CS, menu selection is the most basic operation. in php, it is easy to implement the menu function. the method is as follows: menu. php: Author: christine for people who have used C/S, menu selection is the most basic operation. in php, it is also easy to implement the menu function. the method is as follows:
Menu. php:
//
// Prepared by christine
// Email: greenchn@163.net
//
Class menu {
Var $ name;
Var $ items;
Var $ open;
Var $ closed;
Var $ indent;
Function menu ($ name, $ open = (-), $ closed = (+), $ indent =)
{
$ This-> items = array ();
$ This-> name = $ name;
$ This-> open = $ open;
$ This-> closed = $ closed;
$ This-> indent = $ indent;
}
Function add ($ name, $ href = "", $ target = "")
{
$ N = count ($ this-> items );
If (is_object ($ name ))
{
$ This-> items [$ n] = $ name;
}
Else
{
$ This-> items [$ n] [name] = $ name;
$ This-> items [$ n] [href] = $ href;
$ This-> items [$ n] [target] = $ target;
}
}
Function show ($ nest = 0)
{
$ Urlname = strtr ($ this-> name ,,_);
$ Indent =;
Global $ urlname;
Global $ PHP_SELF;
Global $ QUERY_STRING;
If ($ nest)
{
$ Indent = str_repeat ($ this-> indent, $ nest );
}
If (isset ($ urlname ))
{
Printf (% s
,
$ Indent. $ this-> open,
$ PHP_SELF,
Ereg_replace ("{$ urlname} = &", $ QUERY_STRING ),
$ This-> name );
Echo "n ";
While (list (, $ item) = each ($ this-> items ))
{
If (is_object ($ item ))
{
$ Item-> show ($ nest + 1 );
}
Else
{
Printf (% s
,
$ Indent. $ this-> indent,
$ Item [href],
(! Empty ($ item [target])? Target = ". $ item [target]." :), $ item [name]);
Echo "n ";
}
}
}
Else
{
Printf (% s
,
$ Indent. $ this-> closed,
$ PHP_SELF,
$ Urlname, $ QUERY_STRING,
$ This-> name );
Echo "n ";
}
}
}
?>
Menu2.php:
Include (menu. php );
$ Submenu = new menu (Sub Menu );
$ Submenu-> add (Sub Item 1, vote. php3, _ new );
$ Submenu-> add (Sub Item 2, vote. php3 );
$ Main = new menu (Main );
$ Main-> add (Main Item 1, vote. php3 ?);
$ Main-> add (Main Item 2, vote. php3 );
$ Main-> add ($ submenu );
$ Main-> add (Main Item 3, vote. php3 );
$ Second = new menu (Secondary Menu );
$ Second-> add (Secondary Item 1, vote. php3 );
$ Second-> add (Secondary Item 2, vote. php3 );
$ Main-> show ();
// $ Second-> show ();
?>
Run menu2.php to view the menu effect.
Export menu. php: // Author: christine /...