BBS水木清华站∶精华区

发信人: thinkin (强强), 信区: Linux        
标  题: DebugVariables  
发信站: BBS 水木清华站 (Thu Feb 17 11:03:26 2000) 
 
<?php 
   # coded by thomas hansmann (thomas@thoftware.de) and if you copy it, 
   # you're right ;-) 
   # if you find this code usefull, please send me an email. thanks... 
   # only use the first 2 arguments (a describing name and the variable 
   # itself, $a and $o are used only from within the function). 
  function show_var($n,$v,$a=0,$o=0) { 
    $m1 =  "is an array"; 
    $m2 =  "is an object"; 
    $m3 =  "functions"; 
    $t =  "<table class=debug border=0 cellpadding=0 cellspacing=0>"; 
    if (!$a) echo $t; 
    echo  "<tr><td class=debug valign=top>"; 
    echo ($n ==  "[\"~\"]")? "<br>$m3:&nbsp;": "$n&nbsp;"; 
    echo  "</td><td class=debug>"; 
    if (is_array($v)) { 
      echo ($o? "": "$m1:<br>"). "$t"; 
      for (reset($v);list($k,$vv) = each($v);show_var( "[\"$k\"]",$vv,$a+1)); 
      echo  "</table>"; 
    } elseif (is_object($v)) {                  # very tricky 
      echo  "$m2:<br>"; 
      $v = serialize($v);                       # object -> string 
      $v =  "a".substr($v,1);                    # fake an array 
      $f = unserialize($v);                     # string -> array 
      $v = ereg_replace( "s:[^;]+;i:0;", "",$v);  # delete functions 
      $v = unserialize($v);                     # string -> array 
      for (reset($v);list($key,$val) = each($v);unset($f[$key])); 
      for (reset($f);list($key,$val) = each($f);$v[ "~"].= "$key(); "); 
      show_var( "",$v,$a+1,1); 
    } elseif ($n ==  "[\"~\"]") { 
      echo  "<br>$v<br>"; 
    } elseif (is_string($v)) { 
      echo  ": \"$v\"<br>"; 
    } else echo  "&nbsp;: $v<br>"; 
    echo  "</td></tr>"; 
    if (!$a) echo  "</table>"; 
  } 
?> 
-- 
 
人生到处知何似? 
    应似飞鸿踏雪泥。 
        泥上偶然留指爪, 
            鸿飞那复计东西! 
        
 
※ 来源:·BBS 水木清华站 smth.org·[FROM: 162.105.37.191] 

BBS水木清华站∶精华区