使用pack 填充空白符 unpack解

<?php
$book = array(array('Elmer Gantry', 'Sinclair Lewis', 1927),
              array('The Scarlatti Inheritance', 'Robert Ludlum', '1971'),
              array('The Parsifal Mosaic', 'William Styron', '1979'));
$i = 0;
foreach($book as $bookline){
        $var[$i] = pack('A25A14A4', $bookline[0], $bookline[1], $bookline[2]);
        $i++;
}

print_r ($var);

for($i=0;$i<count($var); $i++){
        $var[$i] = unpack('A25tit/A14aut/A4year', $var[$i]);
}

print_r ($var);
echo $var[1]['tit'];
?>

你可能感兴趣的:(PHP)