Location: PHPKode > scripts > HTML Count > html-count/html_count_class.php
<?php
/**********************************************************************
***********************************************************************
html_count_class.php

This script was writed by Mahesh V. More maheshmore79 at yahoo dot com

This program is freeware software; 

for contact me: http://www.maheshmore.tk
***********************************************************************
***********************************************************************/
/**
 * @class name  html_count
 * @shortdesc   Pattern matching and counting occurrences of HTML tag
 * @author       Mahesh V. More  maheshmore79 at yahoo dot com
 * @version      1.0.0
 * @date          26th October 2005
 * @modified by  
 * @modified on  
 * @methods used  html_count(constructor), call_html_count()
 **/	
class html_count
{
	#
	# stores count of number of tags found
	#
	var $count;
	#
	# stores regular expression pattern used for checking tag
	#
	var $pattern;
	
	/*****************************************************************
	function name: html_count()
	description: constructor
	purpose: to read data from file, calls up the call_html_count() method
	arguments: $file, $pattern
	returns: nothing
	******************************************************************/	
	function html_count($file,$pattern)
	{
		$this->count = 0;
		$this->pattern = $pattern;
		
		$id = @fopen($file,"r");
		
		echo "<ol type=1>";
		while($data = fread($id, 4096)) 
			$this->call_html_count($data);
	
		echo "</ol>";
		fclose($id);
	}
	/*************************************************************************************
	function name: call_html_count()
	description: count tags
	purpose: to perform pattern matching, counts tag and display tag name and  path attribute
	arguments: $contents
	returns: nothing
	**************************************************************************************/
	function call_html_count($contents)
	{
		$matches = array();

		preg_match_all($this->pattern, $contents, $matches);
		//continue until it reaches the end of subject
		
		$this->count += count($matches[2]);
		
		for($i=0;$i<count($matches[2]);$i++)
		{
			echo "<li>";
			echo " Tag : ";
			echo "<font color=blue>";
			echo $matches[1][$i];
			echo "</font>";
			echo " Path : ";
			echo "<font color=blue>";
			echo $matches[2][$i];
			echo "</font>";
			echo "</li>";
		}
	}
}
?> 
Return current item: HTML Count