PHP/Data Structure/unpack
Parsing fixed-width records with unpack()
<source lang="html4strict">
<?php $fp = fopen("data.txt","r") or die ("can"t open file"); while ($s = fgets($fp,1024)) {
$fields = unpack("A25title/A14author/A4publication_year",$s); process_fields($fields);
} fclose($fp) or die("can"t close file"); ?>
</source>
Unpacking Values from Binary Data Using unpack()
<source lang="html4strict">
<?php
$bdata = unpack("nint1/nint2", $data); echo "The first integer in the packed data: {$bdata["int1"]}
"; echo "The second integer in the packed data: {$bdata["int2"]}
";
?>
</source>