Introduction: This is a detailed page for implementing the tree menu style of Windows Resource Manager using PHP. It introduces PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 324021 'rolling = 'no'>
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;
// Take a screenshot of 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];
$ Tree [$ CNT] [3] = $ node [2];
$ Tree [$ CNT] [4] = 0;
If ($ tree [$ CNT] [0]> $ maxlevel) $ maxlevel = $ tree [$ CNT] [0];
$ CNT;
}
Fclose ($ FD );
For ($ I = 0; $ I <count ($ tree); $ I)
{
$ Expand [$ I] = 0;
$ Visible [$ I] = 0;
$ Levels [$ I] = 0;
}
If ($ p! = "")
$ Explevels = explode ("|", $ P );
$ I = 0;
While ($ I <count ($ explevels ))
{
$ Expand [$ explevels [$ I] = 1;
$ I;
}
$ Lastlevel = $ maxlevel;
For ($ I = count ($ tree)-1; $ I> = 0; $ I --)
{
If ($ tree [$ I] [0] <$ lastlevel)
For ($ J = $ tree [$ I] [0] 1; $ j <= $ maxlevel; $ J)
$ Levels [$ J] = 0;
If ($ levels [$ tree [$ I] [0] = 0)
{
$ Levels [$ tree [$ I] [0] = 1;
$ Tree [$ I] [4] = 1;
}
Else
$ Tree [$ I] [4] = 0;
$ Lastlevel = $ tree [$ I] [0];
}
For ($ I = 0; $ I <count ($ tree); $ I)
If ($ tree [$ I] [0] = 1)
$ Visible [$ I] = 1;
For ($ I = 0; $ I <count ($ explevels); $ I)
{
$ N = $ explevels [$ I];
If ($ visible [$ N] = 1) & ($ expand [$ N] = 1 ))
{
$ J = $ n 1;
While ($ tree [$ J] [0]> $ tree [$ N] [0])
{
If ($ tree [$ J] [0] = $ tree [$ N] [0] 1) $ visible [$ J] = 1;
$ J;
}
}
}
For ($ I = 0; $ I <$ maxlevel; $ I)
$ Levels [$ I] = 1;
$ Maxlevel;
Echo "<Table cellspacing = 0 cellpadding = 0 border = 0 Cols =". ($ maxlevel 3). "> \ n ";
Echo "<tr> ";
For ($ I = 0; $ I <$ maxlevel; $ I)
Echo "<TD width = 16> </TD> ";
Echo "<TD width = 100%> & nbsp; </TD> </tr> \ n ";
$ CNT = 0;
While ($ CNT <count ($ tree ))
{
If ($ visible [$ CNT])
{
Echo "<tr> ";
$ I = 0;
While ($ I <$ tree [$ CNT] [0]-1)
{
If ($ levels [$ I] = 1)
Echo "<TD> <a name = '$ CNT'> </a> </TD> ";
Else
Echo "<TD> <a name = '$ CNT'> </a> </TD> ";
$ I;
}
If ($ tree [$ CNT] [4] = 1)
{
Echo "<TD> </TD> ";
$ Levels [$ tree [$ CNT] [0]-1] = 0;
}
Else
{
Echo "<TD> </TD> ";
$ Levels [$ tree [$ CNT] [0]-1] = 1;
}
If ($ tree [$ CNT 1] [0]> $ tree [$ CNT] [0])
{
$ I = 0; $ Params = "? P = ";
While ($ I <count ($ expand ))
{
If ($ expand [$ I] = 1) & ($ CNT! = $ I) | ($ expand [$ I] = 0 & $ CNT = $ I ))
{
$ Params = $ Params. $ I;
$ Params = $ Params. "| ";
}
$ I;
}
If ($ expand [$ CNT] = 0)
Echo "<TD> <a href = \"". $ script. $ Params. "# $ CNT \"> </a> </TD> ";
Else
Echo "<TD> <a href = \"". $ script. $ Params. "# $ CNT \"> </a> </TD> ";
}
Else
Echo "<TD> </TD> ";
If ($ tree [$ CNT] [2] = "")
Echo "<TD colspan = ". ($ maxlevel-$ tree [$ CNT] [0]). "> ". $ tree [$ CNT] [1]. "</TD> ";
Else
Echo "<TD colspan = ". ($ maxlevel-$ tree [$ CNT] [0]). "> <a href = \"". $ tree [$ CNT] [2]. "\" target = \"". $ tree [$ CNT] [3]. "\"> ". $ tree [$ CNT] [1]. "</a> </TD> ";
Echo "</tr> \ n ";
}
$ CNT;
}
Echo "</table> \ n ";
?>
More articles about "using PHP to implement a tree menu in the Windows Resource Manager style"
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/324021.html pageno: 15.