Моя попытка написать инструмент для подсчета голосов в мафии.
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);
}
}
}