Version: 1.0.0

Type: Full Script

Category: HTML

License: GNU General Public License

Description: Helpful for debugging bad HTML code. This program counts the number of opening table tags and how many imbedded tables exist.



<?php

      /** 
      Html table tag analysis: 1.0.0: This program counts the number 
                                      of opening table tags and how 
                                      many imbedded tables exist.

      Copyright (C) 2000  Jeremy Brand 
                          email: jeremy@nirvani.net
                          web: http://www.nirvani.net/jeremy/

      This program is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published by
      the Free Software Foundation; either version 2 of the License, or
      (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      **/

      if ($argc < 2)
      {
        print "argv[1] should be the name of the file you want to parse.\n";
        print "Argv[1] can be a valid URL\n";
        exit(0);
      }

      $array = file($argv[1]);
      $array_size = count($array);

      $max = 0;
      $deep = 0;
      $num_tables = 0;
      $close = 0;

      while(list($key, $val) = each($array))
      {
        if (eregi('<table',$val))
        {
          $num_tables++;
          $deep++;   
          if ($deep > $max)
            $max = $deep;
        }
        else if (eregi('</table',$val))
        {
          $deep--;
        }
        if (eregi('</table',$val))
          $close++;
      }

      print "The total number of open table tags is $num_tables\n";
      print "The total number of close table tags is $close\n";
      if ($close != $num_tables)
        print "Warning: The number of open table tags does not equal the number of close tables tags.  Make sure you check your code!\n\n";
      print "The max depth of imbeded tables is $max\n";


?>