php binary array(二進位陣列) [HOW TO STORE BINARY DATA IN PHP]

php binary array(二進位陣列) [HOW TO STORE BINARY DATA IN PHP]

php binary array(二進位/二進制陣列) [HOW TO STORE BINARY DATA IN PHP]


資料來源: http://www.thecreativedev.com/how-to-store-binary-data-in-php/

https://www.php.net/manual/en/function.unpack.php

https://www.php.net/manual/en/function.pack.php


01.pack()

<?php
$binarydata = pack("nvc*", 0x1234, 0x5678, 65, 66);
?>

02.unpack()

<?php
$binarydata = "\x04\x00\xa0\x00";
$array = unpack("cchars/nint", $binarydata);
print_r($array);
/*
Array
(
    [chars] => 4
    [int] => 160
)
*/
?>
<?php
$binarydata = "\x04\x00\xa0\x00";
$array = unpack("c2chars/nint", $binarydata);
print_r($array);
/*
Array
(
    [chars1] => 4
    [chars2] => 0
    [int] => 40960
)
*/
?>

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *