PHP/Utility Function/pack

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

Format characters for pack( ) and unpack( )

   <source lang="html4strict">

Format character Data type a NUL-padded string A Space-padded string h Hex string, low nibble first H Hex string, high nibble first c signed char C unsigned char s signed short S unsigned short n unsigned short v unsigned short i signed int (machine-dependent size and byte order) I unsigned int (machine-dependent size and byte order) l signed long (32 bit, machine byte order) L unsigned long (32 bit, machine byte order) N unsigned long (32 bit, big endian byte order) V unsigned long (32 bit, little endian byte order) f float (machine-dependent size and representation) d double (machine-dependent size and representation) x NUL byte X Back up one byte @ NUL-fill to absolute position

 </source>
   
  


Generating fixed-width field data records

   <source lang="html4strict">

<?php $books = array( array("A","S",1927),

               array("T","W",1979) );

foreach ($books as $book) {

   print pack("A25A15A4", $book[0], $book[1], $book[2]) . "\n";

} ?>

 </source>