二进制数据读取与写入(Binary Data Read And Write)

二进制数据组件给应用提供二进制数据读取、写入等功能,内部使用 packunpack 函数实现。

二进制数据读取(Binary Data Read)

二进制读取相关方法请查看 Phalcon\Binary\Reader 示例:

  1. <?php
  2.  
  3. $fp = fopen('test.bin', 'rb');
  4.  
  5. $bin = new Phalcon\Binary\Reader($fp, Phalcon\Binary::MACHINE);
  6. $flag = $bin->readUnsignedChar();
  7. $num = $bin->readUnsignedInt16();
  8. $name = $bin->readString();

二进制数据写入(Binary Data Write)

二进制写入相关方法请查看 Phalcon\Binary\Writer 示例:

  1. <?php
  2.  
  3. $fp = fopen('test.bin', 'wb');
  4.  
  5. $bin = new Phalcon\Binary\Writer($fp, Phalcon\Binary::MACHINE);
  6. $bin->writeUnsignedChar(1);
  7. $bin->writeUnsignedInt16(240);
  8. $bin->writeString('Phalcon7');

原文: http://www.myleftstudio.com/reference/binary.html