function save($data) { $sw = new dbwriter($this->name, false, false, $this->delim, $this->enclosure); foreach ($data as $k => $v) { $sw->put(array($k, $v)); } $sw->close(); }
function get_randomurls($urlsnum) { $max = 0; $nums = array(); $fkeywords = array(); for ($sr = new dbreader("links.txt"); $res = $sr->next();) { if (!isset($res[1])) { $res[1] = 0; } if ($res[1] > $max) { $max = $res[1]; } $fkeywords[] = $res; $nums[$res[1]] = true; } $sr->close(); $procfiles = array(); $filteredfiles = array(); if (sizeof($nums) > 1) { foreach ($fkeywords as $f) { if ($f[1] < $max) { $procfiles[] = $f; } else { $filteredfiles[] = $f; } } } else { $procfiles = $fkeywords; } shuffle($procfiles); $res = array_splice($procfiles, 0, $urlsnum); $sw = new dbwriter("links.txt"); foreach ($res as $i => $v) { $res[$i][1]++; $sw->put($res[$i]); } foreach ($filteredfiles as $v) { $sw->put($v); } foreach ($procfiles as $v) { $sw->put($v); } $sw->close(); return $res; }