Use PHP to implement a windows Resource Manager-style tree menu

Source: Internet
Author: User
The following is a tree menu style similar to windows Resource Manager
Include the following script to your page
In addition, you need to extract some GIF images from the resource manager. For more information, see the notes in the script.
The format of the menu structure file is:
Tree level | item text | item link | link target | last item in subtree
For example
. <B> Demo menu </B> | javascript: alert ('This is the demo menu for TreeMenu 1.0 ');
.. <B> directory 1 </B>
... <B> sub-directory 1.1 </B>
... Item 1.1.1 | javascript: alert ('item 1.1.1 ');
... Item 1.1.2 | javascript: alert ('item 1.1.1 ');
... Item 1.2 | javascript: alert ('item 1.2 ');
... Item 1.3 | javascript: alert ('item 1.3 ');
.. <B> subdirectory 2 </B>
... Item 2.1 | javascript: alert ('item 2.1 ');
... Item 2.2 | javascript: alert ('item 2.2 ');
... <B> sub-directory 2.3 </B>
... Item 2.3.1 | javascript: alert ('item 2.3.1 ');
... Item 2.3.2 | javascript: alert ('item 2.3.2 ');
<? Php
// File: tremenu. inc
// PHP TreeMenu
/////////////////
// Initialization //
/////////////////
$ Treefile = "demomenu.txt"; // sets a file with a menu structure.
If (isset ($ PATH_INFO ))
$ Script = $ PATH_INFO;
Else
$ Script = $ SCRIPT_NAME;
// The following figure shows the corresponding position in windows resource manager.
$ Img_expand = "tree_expand.gif"; // scalable node in the resource manager +
$ Img_collapse = "tree_collapse.gif"; // extended node in the resource manager-
$ Img_line = "tree_vertline.gif"; // Image |
$ Img_split = "tree_split.gif"; // Image |-
$ Img_end = "tree_end.gif"; // L-shaped
$ Img_leaf = "tree_leaf.gif"; // o-shaped
$ Img_spc = "tree_space.gif"; // blank figure
// The following is the menu processing script.
$ Maxlevel = 0;
$ Cnt = 0;
$ Fd = fopen ($ treefile, "r ");
If ($ fd = 0) die ("treemenu. inc: Unable to open file". $ treefile );
While ($ buffer = fgets ($ fd, 4096 ))
{
$ Tree [$ cnt] [0] = strspns ($ buffer ,".");
$ Tmp = rtrim (substr ($ buffer, $ tree [$ cnt] [0]);
$ Node = explode ("|", $ tmp );
$ Tree [$ cnt] [1] = $ node [0];
$ Tree [$ cnt] [2] = $ node [1];

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.