PHP咋項函數之pack

來源:互聯網
上載者:User

標籤:style   blog   io   color   ar   os   使用   for   sp   

PHP中不屬性其他類別的函數就叫雜項函數,也屬性PHP的核心組成部分

pack($format,arg+)  //把資料裝入一個二進位的字串中

$format:必選,規定在封裝資料時所使用的格式。
arg+:可選,規定被封裝的一個或多個參數

$format參數的可能值

  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 (always 16 bit, machine byte order)

  S - unsigned short (always 16 bit, machine byte order)

  n - unsigned short (always 16 bit, big endian byte order)

  v - unsigned short (always 16 bit, little endian byte order)

  i - signed integer (machine dependent size and byte order)

  I - unsigned integer (machine dependent size and byte order)

  l - signed long (always 32 bit, machine byte order)

  L - unsigned long (always 32 bit, machine byte order)

  N - unsigned long (always 32 bit, big endian byte order)

  V - unsigned long (always 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

如執行個體:

echo pack("S",80);    //如果格式S後面沒有資料或者具體的數字或者*,則表示後面只能有一個參數,如果後面有具體的數字,則表示後面的參數為這麼多個

//P
echo pack("C3",80,72,80);  //表示後面只能有3個參數//PHP
$str = null;    for($i=0;$i<20;$i++) {        $str .= pack("S",mt_rand(80,128));    }    echo $str;//m{QXim^wslts_W[kvrSU
echo pack("C*",80,72,80);  //表示後面只能有3個參數//PHP

 

PHP咋項函數之pack

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.