try this class.. i wrote it with my function and it's pretty simple.. i haven't tested it yet and i'm waiting for suggestions for optimization from all of you people 
PHP Code:
class power_fetch {
var $url;
var $content;
var $offset;
var $max_offset;
var $src_file;
function power_fetch($url) {
$this->offset = 1;
$this->url = $url;
$this->src_file = tempnam('/tmp', 'src');
copy($this->url, $this->src_file);
$src = fopen($this->src_file, 'r');
if ($src) {
$this->content = fread($src, filesize($this->src_file));
fclose($src);
$this->max_offset = strlen($this->content);
} else {
echo 'ERROR: cannot connect to site (' . $this->url . ')!';
}
}
function destroy() {
unlink($this->src_file);
}
function adv_fetch($start_str, $end_str) {
$start_pos = strpos($this->content, $start_str, $this->offset);
if (($start_pos !== false) AND ($start_pos > $this->offset)) {
$start_pos += strlen($start_str);
$end_pos = strpos($this->content, $end_str, $start_pos);
if ($end_pos !== false) {
if ($end_pos < $this->max_offset) {
$this->offset = $end_pos + strlen($end_str);
}
else {
$this->offset = $this->max_offset;
}
$temp = substr($this->content, $start_pos, ($end_pos-$start_pos));
return $temp;
}
}
return false;
}
}
use it this way:
PHP Code:
mysql_select_db('****', $link);
// Urls to crawl for statistics files
$pf = new power_fetch('http://www.yourdomain.com/_stats.php');
$dest_table = 'site_toplist';
$fields = array('sitename', 'site_desc', 'server_name', 'board_startdate', 'users', 'posts', 'unique_hits');
$sql_unique_field = 'server_name';
// Update sites with new statistics
while ($values = $pf->adv_fetch('<div>', '</div>'))
{
$sql = "UPDATE $dest_table SET ";
$values = explode(',', $values);
foreach ($values as $k => $val)
{
if ($fields[$k] != $sql_unique_field)
{
$sql .= ($fields[$k] . ' = ' . ((is_string($val)) ? ("'$val'") : $val) . ',');
}
else
{
$sql_where = (" WHERE $sql_unique_field = " . ((is_string($val)) ? ("'$val'") : $val));
}
}
$sql = substr($sql, 0, -1); // this will remove the last ','
if (!empty($sql_where)) $sql .= $sql_where;
mysql_query($sql) or die('Could not update the database!');
}
$pf->destroy();
Bookmarks