Форум HeroesWorld-а - Показать сообщение отдельно - Программирование
Показать сообщение отдельно
#74
Старый 28.02.2016, 16:34
  #74
^
KindShaman
 
Аватар для KindShaman
📖
Регистрация: 08.11.2014
Адрес: Н. Новгород
Сообщения: 2205
Регистрация: 08.11.2014
Адрес: Н. Новгород
Сообщения: 2205
Радость
Re: Программирование

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


KindShaman вне форума
Ответить с цитированием