Parsing fixed-width records with unpack()
<?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");
?>
Related examples in the same category