PHP/Data Structure/unpack

Материал из Web эксперт
Перейти к: навигация, поиск

Parsing fixed-width records with unpack()

$fp = fopen("data.txt","r") or die ("can"t open file");
while ($s = fgets($fp,1024)) {
    $fields = unpack("A25title/A14author/A4publication_year",$s);
fclose($fp) or die("can"t close file");

Unpacking Values from Binary Data Using unpack()

     $bdata = unpack("nint1/nint2", $data);
     echo "The first integer in the packed data: {$bdata["int1"]}<BR>";
     echo "The second integer in the packed data: {$bdata["int2"]}<BR>";