Skip to content

Programming

User Avatar
#76
Auto-translated
My attempt to write a tool for counting votes in Mafia.

class Parser{
	public $url=null;
	public $tag=null;
	public $tag_class=null;
	public function setURL($text){
		$this->url=$text;
	}
	public function setSearchTag($text){
		$this->tag=$text;
	}
	public function setTagClass($text){
		if(!empty($text)){
		$this->tag_class=' class="'.$text.'"';
		}else{
			$this->tag_class=null;
		}
	}
	public function parseHTML(){
		if(!empty($this->url)){
		$content = file_get_contents($this->url);
		preg_match_all('/<'.$this->tag.$this->tag_class.'>(.*)<\/'.$this->tag.'>/Uis',$content,$result,PREG_PATTERN_ORDER);
		return $result[0];
		}
	}
}
class Data{
	public $votes = 'votes.txt';
	public function setFilePath($text){
		if(!empty($text)){
			$this->votes = $text;
		}
	}
    public function saveData($data){
		$data = serialize($data);
		file_put_contents($this->votes,$data);
	}
	public function loadData($file){
		if(!empty($file)){
		$data = file_get_contents($file);
		return unserialize($data);
		}
	}
}