<?php
	function NumInstancesOfWord($HayStack, $Needle, $MatchCase = false)
	{
	  $WordArray = array();
		# Make shure masty chars don't affect the results.
		$HayStack  = preg_replace('#[^a-z0-9 ]#si', '' , $HayStack);
	  $HayStack  = strip_tags($HayStack);
		
		if ($MatchCase == false) # Case insensative
		{
	    $WordArray = explode(' ', strtolower($HayStack));
			$$Needle   = strtolower($Needle);
	  }
		else
		{
	    $WordArray = explode(' ', $HayStack);
		}
		
		$CountVar = 0;
		$i        = 0;
		while ($WordArray[$i])
		{
		  if (strrpos($HayStack, $Needle) != false)
			{
			  ++$CountVar;
			}
		  ++$i;
		}
		return ($CountVar);
	}
	$TestStr = implode('', file('http://vbforums.com/showthread.php?p=2338266'));
	echo ('There are ' . NumInstancesOfWord($TestStr, 'slice')    . ' instances of slice.<br />');
?>