Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If someone is still interested here's a sample of mobi metadata reading:</p> <pre><code>class palmDOCHeader { public $Compression = 0; public $TextLength = 0; public $Records = 0; public $RecordSize = 0; } class palmHeader { public $Records = array(); } class palmRecord { public $Offset = 0; public $Attributes = 0; public $Id = 0; } class mobiHeader { public $Length = 0; public $Type = 0; public $Encoding = 0; public $Id = 0; public $FileVersion = 0; } class exthHeader { public $Length = 0; public $Records = array(); } class exthRecord { public $Type = 0; public $Length = 0; public $Data = ""; } class mobi { protected $mobiHeader; protected $exthHeader; public function __construct($file){ $handle = fopen($file, "r"); if ($handle){ fseek($handle, 60, SEEK_SET); $content = fread($handle, 8); if ($content != "BOOKMOBI"){ echo "Invalid file format"; fclose($handle); return; } // Palm Database echo "\nPalm database:\n"; $palmHeader = new palmHeader(); fseek($handle, 0, SEEK_SET); $name = fread($handle, 32); echo "Name: ".$name."\n"; fseek($handle, 76, SEEK_SET); $content = fread($handle, 2); $records = hexdec(bin2hex($content)); echo "Records: ".$records."\n"; fseek($handle, 78, SEEK_SET); for ($i=0; $i&lt;$records; $i++){ $record = new palmRecord(); $content = fread($handle, 4); $record-&gt;Offset = hexdec(bin2hex($content)); $content = fread($handle, 1); $record-&gt;Attributes = hexdec(bin2hex($content)); $content = fread($handle, 3); $record-&gt;Id = hexdec(bin2hex($content)); array_push($palmHeader-&gt;Records, $record); echo "Record ".$i." offset: ".$record-&gt;Offset." attributes: ".$record-&gt;Attributes." id : ".$record-&gt;Id."\n"; } // PalmDOC Header $palmDOCHeader = new palmDOCHeader(); fseek($handle, $palmHeader-&gt;Records[0]-&gt;Offset, SEEK_SET); $content = fread($handle, 2); $palmDOCHeader-&gt;Compression = hexdec(bin2hex($content)); $content = fread($handle, 2); $content = fread($handle, 4); $palmDOCHeader-&gt;TextLength = hexdec(bin2hex($content)); $content = fread($handle, 2); $palmDOCHeader-&gt;Records = hexdec(bin2hex($content)); $content = fread($handle, 2); $palmDOCHeader-&gt;RecordSize = hexdec(bin2hex($content)); $content = fread($handle, 4); echo "\nPalmDOC Header:\n"; echo "Compression:".$palmDOCHeader-&gt;Compression."\n"; echo "TextLength:".$palmDOCHeader-&gt;TextLength."\n"; echo "Records:".$palmDOCHeader-&gt;Records."\n"; echo "RecordSize:".$palmDOCHeader-&gt;RecordSize."\n"; // MOBI Header $mobiStart = ftell($handle); $content = fread($handle, 4); if ($content == "MOBI"){ $this-&gt;mobiHeader = new mobiHeader(); echo "\nMOBI header:\n"; $content = fread($handle, 4); $this-&gt;mobiHeader-&gt;Length = hexdec(bin2hex($content)); $content = fread($handle, 4); $this-&gt;mobiHeader-&gt;Type = hexdec(bin2hex($content)); $content = fread($handle, 4); $this-&gt;mobiHeader-&gt;Encoding = hexdec(bin2hex($content)); $content = fread($handle, 4); $this-&gt;mobiHeader-&gt;Id = hexdec(bin2hex($content)); echo "Header length: ".$this-&gt;mobiHeader-&gt;Length."\n"; echo "Type: ".$this-&gt;mobiHeader-&gt;Type."\n"; echo "Encoding: ".$this-&gt;mobiHeader-&gt;Encoding."\n"; echo "Id: ".$this-&gt;mobiHeader-&gt;Id."\n"; fseek($handle, $mobiStart+$this-&gt;mobiHeader-&gt;Length, SEEK_SET); $content = fread($handle, 4); if ($content == "EXTH"){ $this-&gt;exthHeader = new exthHeader(); echo "\nEXTH header:\n"; $content = fread($handle, 4); $this-&gt;exthHeader-&gt;Length = hexdec(bin2hex($content)); $content = fread($handle, 4); $records = hexdec(bin2hex($content)); echo "Records: ".$records."\n"; for ($i=0; $i&lt;$records; $i++){ $record = new exthRecord(); $content = fread($handle, 4); $record-&gt;Type = hexdec(bin2hex($content)); $content = fread($handle, 4); $record-&gt;Length = hexdec(bin2hex($content)); $record-&gt;Data = fread($handle, $record-&gt;Length - 8); array_push($this-&gt;exthHeader-&gt;Records, $record); echo "Record ".$i." type: ".$record-&gt;Type." length: ".$record-&gt;Length."\n"; echo " data: ".$record-&gt;Data."\n"; } } } fclose($handle); } } protected function GetRecord($type) { foreach ($this-&gt;exthHeader-&gt;Records as $record){ if ($record-&gt;Type == $type) return $record; } return NULL; } protected function GetRecordData($type) { $record = $this-&gt;GetRecord($type); if ($record) return $record-&gt;Data; return ""; } public function Title() { return $this-&gt;GetRecordData(503); } public function Author() { return $this-&gt;GetRecordData(100); } public function Isbn() { return $this-&gt;GetRecordData(104); } public function Subject() { return $this-&gt;GetRecordData(105); } public function Publisher() { return $this-&gt;GetRecordData(101); } } $mobi = new mobi("test.mobi"); echo "\nTitle: ".$mobi-&gt;Title(); echo "\nAuthor: ".$mobi-&gt;Author(); echo "\nIsbn: ".$mobi-&gt;Isbn(); echo "\nSubject: ".$mobi-&gt;Subject(); echo "\nPublisher: ".$mobi-&gt;Publisher(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload