PHP code example of pburggraf / binary-utils
1. Go to this page and download the library: Download pburggraf/binary-utils library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pburggraf / binary-utils example snippets
PBurggraf\BinaryUtilities\BinaryUtilityFactory;
use \PBurggraf\BinaryUtilities\DataType\Byte;
file_put_contents('/tmp/temp.txt', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ');
$binaryUtility = BinaryUtilityFactory::create();
// Read data
$result = $binaryUtility
->setFile('/tmp/temp.txt')
->setOffset(0x08)
->readArray(Byte::class, 4)
->returnBuffer();
var_dump($result);
// Expected result:
// array(4) {
// [0] =>
// string(2) "56"
// [1] =>
// string(2) "57"
// [2] =>
// string(2) "65"
// [3] =>
// string(2) "66"
// }
// Write data
$binaryUtility
->setOffset(0x08)
->writeArray(Byte::class, [66, 65, 57, 56])
->save();
var_dump(file_get_contents('/tmp/temp.txt'));
// Expected result:
// string(36) "01234567BA98CDEFGHIJKLMNOPQRSTUVWXYZ"