/** * @param int $limit * @return array */ function getLastQueries($limit = 10) { $results = Memcache\Handler::factory()->cache('now', 5, function () { $source = Sunra\PhpSimple\HtmlDomParser::file_get_html('http://mp3skull.com/latest.html'); $links = $source->find('#content a'); $result = []; foreach ($links as $link) { $result[] = $link->innertext; } return $result; }); if (count($results) <= $limit) { return $results; } return array_slice($results, 0, $limit); }
/** * @param int $id * @param string $url * * @return array */ private function findNewsData($id, $url) { $newsData = []; $parser = new \Sunra\PhpSimple\HtmlDomParser(); $htmlNews = $parser->file_get_html($url); if ($id == 1) { $newsData['title'] = $htmlNews->find('h1', 0); $newsData['content'] = $htmlNews->find('div.main_news_detail div.description div.text', 0); } elseif ($id == 2) { $newsData['title'] = $htmlNews->find('div.lside h1', 0); $newsData['content'] = $htmlNews->find('div.lside div.fnblk div.fntxt', 0); } elseif ($id == 3) { $newsData['title'] = $htmlNews->find('div#content-middle h1', 0); $newsData['content'] = $htmlNews->find('div#content-middle div[class="simple-content mt15"] div[class="simple-content mt25"]', 0); } elseif (in_array($id, [4, 5])) { $newsData['title'] = $htmlNews->find('div.reader_article h3.reader_article_headline', 0); $newsData['content'] = $htmlNews->find('div.reader_article div.reader_article_body', 0); } elseif ($id == 6) { $newsData['title'] = $htmlNews->find('h2.content__title', 0); $newsData['content'] = $htmlNews->find('div.article__text', 0); } return $newsData; }