Byte manipulation in PHP

Posted by Michael Angstadt on Stack Overflow See other posts from Stack Overflow or by Michael Angstadt
Published on 2010-12-31T15:14:10Z Indexed on 2011/01/04 20:54 UTC
Read the original article Hit count: 105

Filed under:
|

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?

Right now, I'm treating it like a string, using the substr() function:

$data = //...
$first8Bytes = substr($data, 0, 8);

Is it safe to use substr with binary data?

Or are there other functions that I should be using?

Thanks.

© Stack Overflow or respective owner

Related posts about php

Related posts about byte