唠叨帮忙看看这个代码在PHP5上怎么提示错误 在PHP4上运行正常

haihaiff 2006-10-19 04:08:19
真不想麻烦你了 但是我搞了老半天 一点头续都没有 老说什么数组错误
<?php
class TreeMenu
{
var $tree = array();
var $expAND = array();
var $visible = array();
var $levels = array();
var $explevels = array();
var $urlparams = array();
var $maxlevel = 0;
var $i = 0;
var $urlparam;
var $script;
var $layer= 1;
var $img_expAND = "treemenu/tree_expAND.png";
var $img_collapse = "treemenu/tree_collapse.png";


function treemenu($urlparam, $nodefile = ""){

$this->script = isset($GLOBALS["PATH_INFO"])? $GLOBALS["PATH_INFO"] : $GLOBALS["SCRIPT_NAME"];
$this->urlparam = "tmv".$urlparam;

//reset($GLOBALS["HTTP_GET_VARS"]);
while (list($key,) = each ($GLOBALS["HTTP_GET_VARS"])){
//$this->urlparams[] = $key;
$this->urlparams = $_GET;
}
if (!empty($nodefile)) $this->loadTreeFROMFile($nodefile);

}

function createMenu($path) {
if ($handle = opendir($path)) {
while (false !== ($file= readdir($handle))) {
if ($file != "." && $file != "..") {
if(is_dir($path."/".$file)) {
$this->layer++;
$this->addNode($this->layer, $file.$level);
$this->createMenu($path."/".$file);
$this->layer--;
}
}
}
closedir($handle);
}
}

function addNode($level, $text, $link = "", $target = ""){
$this->tree[$this->i][0] = $level;
$this->tree[$this->i][1] = "<nobr>".$text."</nobr>";
$this->tree[$this->i][2] = $link;
$this->tree[$this->i][3] = $target;
$this->tree[$this->i][4] = 0;

if ($this->tree[$this->i][0] > $this->maxlevel) $this->maxlevel = $this->tree[$this->i][0];

$this->expAND[$this->i]=0;
$this->visible[$this->i]=0;
$this->levels[$this->i]=0;

$this->i++;
}

function loadTreeFROMFile($nodefile){
$fd = fopen($nodefile, "r");
if ($fd == 0) die($this->script." : Unable to open file ".$nodefile);
while ($buffer = fgets($fd, 4096)){
$level = strspn($buffer,".");
$node = explode("|", rtrim(substr($buffer,$level)));
$text = $node[0];
$link = $node[1];
$target = $node[2];
$this->addNode($level, $text, $link, $target);
}
fclose($fd);
}

function loadTreeFormString($text) {
if($text!= "") {
$line= explode("", $text);
$i= 0;
while ($line[$i]!= "") { //读取一行
$level = strspn($line[$i], ".");
$node = explode("|", rtrim(substr($line[$i],$level)));
$text = $node[0];
$link = $node[1];
$target = $node[2];
$this->addNode($level, $text, $link, $target);
$i++;
}
}
}

function setExpANDedNodesFROMURL(){
if (!empty($GLOBALS[$this->urlparam])) $this->explevels = explode("|",$GLOBALS[$this->urlparam]);
$this->setExpANDedNodes();
}

function setExpANDedNodes(){
$i=0;
while($i<count($this->explevels)){
$this->expAND[$this->explevels[$i]]=1;
$i++;
}
}

function setEndNodes(){
$lastlevel=$this->maxlevel;
for ($i=count($this->tree)-1; $i>=0; $i--){
if ( $this->tree[$i][0] < $lastlevel ){
for ($j=$this->tree[$i][0]+1; $j <= $this->maxlevel; $j++){
$this->levels[$j]=0;
}
}

if ( $this->levels[$this->tree[$i][0]]==0 ){
$this->levels[$this->tree[$i][0]]=1;
$this->tree[$i][4]=1;
} else {
$this->tree[$i][4]=0;
}
$lastlevel=$this->tree[$i][0];
}
}

function setVisibleNodes(){
// all root nodes are always visible
for ($i=0; $i < count($this->tree); $i++){
if ($this->tree[$i][0]==1){
$this->visible[$i]=1;
}
}

for ($i=0; $i < count($this->explevels); $i++){
$n = $this->explevels[$i];
if ( ($this->visible[$n]==1) && ($this->expAND[$n]==1) ){
$j=$n+1;
while ( $this->tree[$j][0] > $this->tree[$n][0] ){
if ($this->tree[$j][0]==$this->tree[$n][0]+1) $this->visible[$j]=1;
$j++;
}
}
}
}

function show(){
echo $this->getHTMLTable();
}


function getHTMLTable(){

$this->setExpANDedNodesFROMURL();
$this->setEndNodes();
$this->setVisibleNodes();

/*********************************************
* Output nicely formatted tree *
*********************************************/

for ($i=0; $i<$this->maxlevel; $i++) $this->levels[$i]=1;

$this->maxlevel++;

$html = "<table cellspacing=0 cellpadding=0 border=0 cols=".($this->maxlevel+3)." width=100%>\n";
$html .= "<tr>";

for ($i=0; $i<($this->maxlevel+3); $i++) $html .= "<td width=16></td>";
$html .= "<td width=100%> </td></tr>\n";

$cnt=0;

while ($cnt<count($this->tree)){
if ($this->visible[$cnt]){

/****************************************
* start new row *
****************************************/

$html .= "<tr>";

/****************************************
* vertical lines FROM higher levels *
****************************************/

$i=0;
while ($i<$this->tree[$cnt][0]-1){
if ($this->levels[$i]==1){
$html .= "<td><a name='$cnt'></a><img src=\"".$this->img_line."\"></td>";
} else {
$html .= "<td><a name='$cnt'></a><img src=\"".$this->img_spc."\"></td>";
}
$i++;
}

/****************************************
* corner at end of subtree OR t-split *
****************************************/

if ($this->tree[$cnt][4]==1){
$html .= "<td><img src=\"".$this->img_end."\"></td>";
$this->levels[$this->tree[$cnt][0]-1]=0;
} else {
$html .= "<td><img src=\"".$this->img_split."\"></td>";
$this->levels[$this->tree[$cnt][0]-1]=1;
}

/********************************************
* Node (with subtree) OR Leaf (no subtree) *
********************************************/

if ($this->tree[$cnt+1][0]>$this->tree[$cnt][0]){

/****************************************
* Create expAND/collapse parameters *
****************************************/

//reset($this->urlparams);
while (list(,$value) = each ($this->urlparams)){
if (!empty($GLOBALS[$value]) && $value <> $this->urlparam) {
$otherparams .= $value."=".$GLOBALS[$value]."&";
}
}

$params="?".$otherparams.$this->urlparam."=";

$i=0;
while($i<count($this->expAND)){
if ( ($this->expAND[$i]==1)
&& ($cnt!=$i)
|| ($this->expAND[$i]==0 && $cnt==$i)){

$params=$params.$i;
$params=$params."|";
}
$i++;
}

$otherparams = "";

if ($this->expAND[$cnt]==0){
$html .= "<td><a href=\"".$this->script.$params."#$cnt\"><img src=\"".$this->img_expAND."\" border=no></a></td>";
} else {
$html .= "<td><a href=\"".$this->script.$params."#$cnt\"><img src=\"".$this->img_collapse."\" border=no></a></td>";
}

} else {

/*************************
* Tree Leaf *
*************************/

$html .= "<td><img src=\"".$this->img_leaf."\"></td>";
}

/****************************************
* output item text *
****************************************/

if ($this->tree[$cnt][2]==""){
$html .= "<td colspan=".($this->maxlevel-$this->tree[$cnt][0]).">".$this->tree[$cnt][1]."</td>";
} else {
$html .= "<td colspan=".($this->maxlevel-$this->tree[$cnt][0])."><a href=\"".$this->tree[$cnt][2]."\" target=\"".$this->tree[$cnt][3]."\">".$this->tree[$cnt][1]."</a></td>";
}

/****************************************
* end row *
****************************************/

$html .= "</tr>\n";
}

$cnt++;
}

$html .= "</table>\n";
return $html;
}
}


?>
...全文
228 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
an9ryfr09 2006-10-20
  • 打赏
  • 举报
回复
我这里得到的只是notice和warning。
你在程序顶部加入ini_set('display_errors','off');试试看能否运行
haihaiff 2006-10-20
  • 打赏
  • 举报
回复
我知道我不应该发那么长的贴子 但是等了老半天也灭有人回答 叫我删贴也不是 给分也不是
NND
haihaiff 2006-10-19
  • 打赏
  • 举报
回复
<?php
include "treemenu.inc";
$tree = new treemenu("a");
$tree->addNode(1, "grANDpa");
$tree->addNode(2, "pa");
$tree->addNode(3, "son");
$tree->addNode(2, "uncle");
$tree->loadTreeFROMFile("demomenu.txt");

$tree->show();
?>
就是这样调用的啊
an9ryfr09 2006-10-19
  • 打赏
  • 举报
回复
你是不是调用的时候传值错误?这个类本身没有语法错误
xuzuning 2006-10-19
  • 打赏
  • 举报
回复
你是如何调用的

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧