file = fopen($file, 'rb'); } public function load() { // checks if file is opened correctly if ($this->file) { // skips version fseek($this->file, 4); // reads nodes chain while (!feof($this->file)) { // reads byte switch (ord(fgetc($this->file))) { // maybe a town node case self::NODE_START: // reads node type if (ord(fgetc($this->file)) == self::OTBM_TOWN) { $id = unpack('L', fread($this->file, 4)); $length = unpack('S', fread($this->file, 2)); // reads town name $this->towns[$id[1]] = fread($this->file, $length[1]); } break; // escape next character - it might be NODE_START character which is in fact not case self::ESCAPE_CHAR: fgetc($this->file); break; } } } } public function get() { return $this->towns; } }