Beispiel #1
0
 public static function find_all_instances_in_category($categoryId, $filename = "data/text.mdb")
 {
     $in = MMDBParser::open_file();
     if ($in === null) {
         return null;
     }
     // start at offset = 8 since that is where the categories start
     // find the category
     $category = MMDBParser::find_entry($in, $categoryId, 8);
     if ($category === null) {
         echo "Could not find categoryID: '{$categoryId}'\n";
         fclose($in);
         return null;
     }
     // find all instances
     $instances = array();
     fseek($in, $category['offset']);
     do {
         $previousInstance = $instance;
         $instance = MMDBParser::read_entry($in);
         $instances[] = $instance;
     } while ($previousInstance == null || $instance['id'] > $previousInstance['id']);
     // for each instance found, get the message and add to array (instanceId => message)
     $array = array();
     foreach ($instances as $instance) {
         fseek($in, $instance['offset']);
         $message = MMDBParser::read_string($in);
         $array[$instance['id']] = $message;
     }
     return $array;
 }