Php creation menu

Source: Internet
Author: User
For those who have used C/S, menu selection is the most basic operation. in php, it is easy to implement the menu function. the method is as follows: menu. php: menu2.php: run menu2.php to view the menu effect. SyntaxHighlighter. all ();

For people who have used C/S, menu selection is the most basic operation. in php, it is 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.