<?php
$basedir = $GLOBALS[DOCUMENT_ROOT];
$wdir = "/nikar/";
$srcpat = "([sS][rR][cC]=\"([\"]+)\")";
$hrefpat = "([hH][rR][eE][fF]=\"([\"]+)\")";
$bkgpat = "([bB][aA][cC][kK][gG][rR][oO][uU][nN][dD]=\"([\"]+)\")";
$sum = 0;
function find_obj($pattern, $string)
{
global $basedir;
if (preg_match_all($pattern, $string, $Matches))
{
array_shift($Matches);
foreach($Matches as $match)
{
$src_list[] = $match;
}
while (list($key, $var) = each($match))
{
$objsize = filesize($basedir."/".$var);
$sum+=$objsize;
echo "$key => $var size = $objsize bytes<br>";
}
}
return $sum;
}
$sum+=find_obj($srcpat, $ObjStr);
$sum+=find_obj($hrefpat, $ObjStr);
$sum+=find_obj($bkgpat, $ObjStr);
echo "total object size = ".$sum;
?>
that should work, I haven't tested it though.
Really all you need to do is get rid of the static var line and add $sum+= to your find_obj calls.
You also had a few global vars in there which didn't seem to need to be there, so I took them out.
HTH