function collect_rss($rss, $cat_id) { global $db, $table, $upload_dir; $rss = file_get_contents($rss); $rss = mb_convert_encoding($rss, 'utf-8', 'gbk'); $rss = str_replace('gb2312', 'utf-8', $rss); $xml = simplexml_load_string($rss); foreach ($xml->channel->item as $item) { $exist = $db->get_col("SELECT COUNT(*) FROM {$table} WHERE title = ?", array($item->title)); if ($exist) { continue; } $article = array(); $article['cat_id'] = $cat_id; $article['title'] = $item->title; $article['link'] = $item->link; $article['pub_date'] = date('Y-m-d H:i:s', strtotime($item->pubDate)); $article['add_time'] = date('Y-m-d H:i:s'); $article['source'] = $item->source; $article['author'] = $item->author; $article['cover_image'] = cover_image($item->description, $upload_dir); $article['description'] = trim(strip_tags($item->description)); $db->insert($table, $article); } }
$this->newKey($uid); } return $key; } public function test() {