home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / php.exe / Print.php < prev    next >
Encoding:
PHP Script  |  2001-07-02  |  3.6 KB  |  114 lines

  1.     //**************************************
  2.     //     
  3.     // Name: Print Array
  4.     // Description:Print Array is most usefu
  5.     //     l as a debugging function, when you want
  6.     //     to see the exact structure contained wit
  7.     //     hin a variable. By Scott Parish
  8.     // By: PHP Code Exchange
  9.     //**************************************
  10.     //     
  11.     
  12.     <?php
  13.     /* FIRETAIL-print_array
  14.     * Copyright (C) 1999 Scott Parish
  15.     *
  16.     * This library is free software; you can redistribute it and/or
  17.     * modify it under the terms of the GNU Library General Public
  18.     * License as published by the Free Software Foundation; either
  19.     * version 2 of the License, or (at your option) any later version.
  20.     *
  21.     * This library is distributed in the hope that it will be useful,
  22.     * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23.     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24.     * Library General Public License for more details.
  25.     *
  26.     * You should have received a copy of the GNU Library General Public
  27.     * License along with this library; if not, write to the
  28.     * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  29.     * Boston, MA 02111-1307, USA.
  30.     */
  31.     //This is are two little functions that 
  32.     //     I made to quickly debug my arrays
  33.     //while making php scripts. You can pass
  34.     //     these things any variable (both
  35.     //arrays and non arrays), and it will pr
  36.     //     int out everything that is in it.
  37.     //It will even print out embedded arrays
  38.     //     , so if you have arrays in arrays
  39.     //in arrays, it will print all that out 
  40.     //     in a consice enough format that you
  41.     //will know exactly what is in that vari
  42.     //     able.
  43.     //
  44.     //You should get output with "key => 
  45.     //     val", which should look something like
  46.     //the following:
  47.     //
  48.     // admin =>
  49.     // user=> 1
  50.     // screwball => 2
  51.     // admin => 4
  52.     // . . .
  53.     // is=>
  54.     // student worker => 1
  55.     // hacker => 2
  56.     // nerd=> 4
  57.     // admin => 8
  58.     // . . .
  59.     // 
  60.     //call it like the following (where $tes
  61.     //     tVar is a variable of you choice)
  62.     //
  63.     // print_array($testVar);
  64.     //
  65.     //if your array contains any html code, 
  66.     //     you may want to call it instead as:
  67.     //
  68.     // print_array($testVar,"<xmp>","&
  69.     //     lt;/xmp>");
  70.     // 
  71.     //Should be very easy to throw in your c
  72.     //     ode and use...hope you find it useful
  73.     //Scott Parish <sRparish@bigfoot.com&
  74.     //     gt; 1998/02/24
  75.     
  76.     if(!$GLOBALS["PRINT_ARRAY"]) {
  77.     $GLOBALS["PRINT_ARRAY"]=true;
  78.     function print_array($a,$btag="",$etag="") {
  79.     if(is_array($a)) {
  80.     printf("<table cellpadding=0 cellspacing=0>");
  81.     while(list($one,$two)=each($a)) {
  82.     printf("\n<tr valign=baseline><td>$btag$one$etag</td><td>".
  83.     " $btag=>$etag</td>".
  84.     "<td align=right> %s</td></tr>\n"
  85.     ,sprint_array($two,$btag,$etag));
  86.     }
  87.     printf("</table>");
  88.     } 
  89.     else {
  90.     printf("%s%s%s",$btag,$a,$etag);
  91.     } 
  92.     }
  93.     
  94.     
  95.     function sprint_array($a,$btag="",$etag="") {
  96.     if(is_array($a)) {
  97.     $out=sprintf("<table cellpadding=0 cellspacing=0>");
  98.     while(list($one,$two)=each($a)) {
  99.     $out .= sprintf("\n<tr valign=baseline><td>$btag$one$etag</td><td>".
  100.     " $btag=>$etag</td>".
  101.     "<td align=right> %s</td></tr>\n"
  102.     ,sprint_array($two,$btag,$etag));
  103.     }
  104.     $out .= "</table>";
  105.     return $out;
  106.     }
  107.     else {
  108.     return sprintf("%s%s%s",$btag,$a,$etag);
  109.     }
  110.     }
  111.     }
  112.     ?>
  113.  
  114.