title: Strange behavior reading DBF file in PHP using fread()
body: <p>I have a DBF file created as part of a shapefile with <code>rgdal</code> library's <code>writeOGR</code> function (in R).</p>
  
  <p>When I ask to see its first bytes with Linux <code>od</code> command, I get the following.</p>
  
  <pre><code>od -x -c -N 32 BRA.dbf
  0000000 7703 1e07 001b 0000 00a1 00d1 0000 0000
  0000020 0000 0000 0000 0000 0000 0000 5700 0000
  0000040
  </code></pre>
  
  <p>My PHP code goes like this.</p>
  
  <pre><code>$dbf = fopen('BRA.dbf','rb');
  fread($dbf,10); // jumps over the first 10 bytes
  $dbfRecSize = unpack('v',fread($dbf,2))[1]; // 'v' = little endian 16 bits: 00d1 = d1(16) = 209
  fread($dbf,17); // jumps over a few more bytes
  $dbfLangID = ord(fread($dbf,1)); // language driver ID
  if ($dbfLangID == 0x57) {
      echo "Language: 0x57 (ISO-8859-1)\n";
  } else {
      echo "Language: $dbfLangID;\n";
  }
  </code></pre>
  
  <p>The code above outputs "Language: 0x57 (ISO-8859-1)", which means the "57" close to the end of the <code>od</code> output is being read with the <code>ord(fread($dbf,1));</code> command.</p>
  
  <p>Strange thing is that I've read 10+2+17 = 29 bytes from the file, so the next byte should be "00", or not (right after the 0x57)? <code>$dbfRecSize</code> is 209, which means my logic is correct in the first two reads. Why isn't it in the following reads?</p>
  
  <p>What am I misunderstanding here?</p>