title: Byte manipulation in PHP
body: <p>In PHP, if you have a variable with binary data, how do you get specific bytes from the data?  For example, if I have some data that is 30 bytes long how do I get the first 8 bytes?</p>
  
  <p>Right now, I'm treating it like a string, using the <code>substr()</code> function:</p>
  
  <pre><code>$data = //...
  $first8Bytes = substr($data, 0, 8);
  </code></pre>
  
  <p><strong>Is it safe to use <code>substr</code> with binary data?</strong></p>
  
  <p>Or are there other functions that I should be using?</p>