PATH://adammoro.net/code/php/

PHP Function: Tag Count

This counts the number of specific tags on a web page. For example, it will tell you how many <H1> and <A> tags are present in addition to several other common HTML tags.

            <?php function tag_count($domain) {
              $data = file_get_contents($domain);
              $data = strtoupper($data);
              $h1 = substr_count($data,'<H1');
              $h2 = substr_count($data,'<H2');
              $h3 = substr_count($data,'<H3');
              $h4 = substr_count($data,'<H4');
              $h5 = substr_count($data,'<H5');
              $h6 = substr_count($data,'<H6');
              $bold = substr_count($data,'<B>');
              $bold += substr_count($data,'<STRONG>');
              $italic = substr_count($data,'<I>');
              $italic += substr_count($data,'<ITALIC>');
              $italic += substr_count($data,'<EM>');
              $underline = substr_count($data,'<UNDERLINE>');
              $underline += substr_count($data,'<U>');
              $links = substr_count($data,'<A');
              $img = substr_count($data,'<IMG');
              $script = substr_count($data,'<SCRIPT');
              $table = substr_count($data,'<TABLE');
              $div = substr_count($data,'<DIV');
              //-output
              echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
              echo "<tr><td>H1: {$h1}</td><td>H4: {$h4}</td><td>U/UNDERLINE: {$underline}</td><td>SCRIPT: {$script}</td></tr>";
              echo "<tr><td>H2: {$h2}</td><td>B/STRONG: {$bold}</td><td>IMG: {$img}</td><td>TABLE: {$table}</td></tr>";
              echo "<tr><td>H3: {$h3}</td><td>I/EM/ITALIC: {$italic}</td><td>A: {$links}</td><td>DIV: {$div}</td></tr>";
              echo "</table>";
            } ?>