phpbar.de logo

Mailinglisten-Archive

[php] Re: =?iso-8859-1?Q?Infos_=FCber_Variable_herausfinden=3F?=

[php] Re: =?iso-8859-1?Q?Infos_=FCber_Variable_herausfinden=3F?=

Martin Ramsch m.ramsch_(at)_computer.org
Sat, 11 Sep 1999 15:08:08 +0200


--x+6KMIRAuhnl3hBn
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Ich schrieb vorher:
> Die aktuelle Form von SHOW findet Ihr im Anhang.

Typisch, den Anhang hatte ich natürlich vergessen ... ;-)

Hier ist er.

Ciao,
  Martin

--x+6KMIRAuhnl3hBn
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="showvar.php3"

<?php

  /* Preliminary measures: */
  $selfphp = ereg_replace("^.*/",     "",     $PHP_SELF);
  $selftxt = ereg_replace("\.php3$", ".phps", $selfphp);
  $version = "PHP " . phpVersion();

Function SHOW ( $value, $var = 1, $indent = 23 ) {
  // var==1: show the variable with name $value
  // var==0: return the content of $value

  if($var) {
    $varname = $value; $value = $GLOBALS[$varname];
  }
  $typ = ucfirst(gettype($value));
  switch($typ) {
    case "Integer":
      $content = (string)$value;
      break;
    case "Double":
      $content = (string)$value;
      break;
    case "String":
      // $content = "'".ereg_replace('([\'\\])','\\\\1',${value})."'";
      $content = "»${value}«";
      break;
    case "Array":
    case "Object":
      $content = "( ";
      while( list($key, $val) = each($value) ) {
        $keyval = SHOW($key,0,0);
        $content .= sprintf("%s => %s,\n%${indent}s",
                            $keyval,
                            SHOW($val,0,16+$indent+strlen($keyval)), '' );
      }
      $content = ereg_replace(',[^,]*$','',$content);
      $content .= ' )';
      break;
    case "Unknown Type":
      $content = (string)$value;
      break;
    default:                    break;
  }

  if ($var):
    echo HtmlSpecialChars(
           sprintf("%8s = %9s %s\n\n", '$'.$varname, "($typ)", $content)
         );
  else:
    $result = sprintf("%9s %s", "($typ)", $content);
    return $result;
  endif;
}

?>

  Martin Ramsch test page: SHOW



Interested in the PHP3 source
of this page?
Used version of PHP is: .

SHOWVAR