Home >php教程 >php手册 >用PHP实现windows资源管理器风格的树型菜单

用PHP实现windows资源管理器风格的树型菜单

WBOY
WBOYOriginal
2016-06-13 09:59:45822browse

以下是一个风格类似windows资源管理器的树型菜单
将下面的脚本包含到你的页面中
另外需要从资源管理器中截取一些gif图片,祥见脚本中的注释
菜单结构文件的格式为:
tree level|item text|item link|link target|last item in subtree
例如
.Demo menu|javascript: alert('This is the demo menu for TreeMenu 1.0');
..目录1
...子目录 1.1
....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');
..子目录 2
...item 2.1|javascript: alert('Item 2.1');
...item 2.2|javascript: alert('Item 2.2');
...子目录 2.3
....item 2.3.1|javascript: alert('Item 2.3.1');
....item 2.3.2|javascript: alert('Item 2.3.2');
// file:tremenu.inc
// PHP TreeMenu
/////////////////
// 初始化 //
/////////////////
$treefile = "demomenu.txt";//设置有菜单结构的文件
if(isset($PATH_INFO))
$script = $PATH_INFO;
else
$script = $SCRIPT_NAME;
//以下图片可截取windows资源管理器中的相应位置的图
$img_expand = "tree_expand.gif";//形如资源管理器中可扩展节点+
$img_collapse = "tree_collapse.gif";//形如资源管理器中已扩展节点-
$img_line = "tree_vertline.gif";//形如|
$img_split = "tree_split.gif";//形如|-
$img_end = "tree_end.gif";//形如L
$img_leaf = "tree_leaf.gif";//形如o
$img_spc = "tree_space.gif";//空白图
//以下是菜单处理脚本
$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]=strspn($buffer,".");
$tmp=rtrim(substr($buffer,$tree[$cnt][0]));
$node=explode("|",$tmp);
$tree[$cnt][1]=$node[0];
$tree[$cnt][2]=$node[1];

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn