<?php 
class StringParser {
	/**
	 * fileName to search in
	 */
	protected $fileName;
	protected $fileContents;
	
	/**
	 * set the file name $fileName
	 */
	function __construct($fileName){
		$this->setFileName($fileName);
		$this->setFileContents(file_get_contents($fileName));
	}
	
	/**
	 *  calculate number of each character sequence occurrence using str_replace
	 */
	function countOccurrenceUsingStringReplace($search){
		str_replace($search, "", $this->getFileContents(),$count);
		return $count;
	}
	
	/**
	 *  calculate number of each character sequence occurrence using substr_count
	 */
	function countOccurrenceUsingSubstrCount($search){
		return substr_count($this->getFileContents(), $search);
	}
	
	/**
	 *  calculate number of each character sequence occurrence using preg_match_all
	 */
	function countOccurrenceUsingpregMatchAll($search){
		return preg_match_all('/'.$search.'/i', $this->getFileContents(), $matches);
	}
	
	/**
	 * @return the $fileName
	 */
	public function getFileName() {
		return $this->fileName;
	}

	/**
	 * @param string $fileName
	 */
	public function setFileName($fileName) {
		$this->fileName = $fileName;
		return $this;
	}
	
	/**
	 * @return the $fileContents
	 */
	public function getFileContents() {
		return $this->fileContents;
	}

	/**
	 * @param string $fileContents
	 */
	public function setFileContents($fileContents) {
		$this->fileContents = $fileContents;
		return $this;
	}


	
}
?>