成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導(dǎo)航首頁 ? 技術(shù)教程 ? PHP:pack()的用法_misc函數(shù)
全站頭部文字 我要出現(xiàn)在這里
PHP:pack()的用法_misc函數(shù) 778 2023-12-15   

pack

(PHP 4, PHP 5)

pack — Pack data into binary string

說明

string pack ( string $format [, mixed $args [, mixed $... ]] )

Pack given arguments into a binary string according to format.

The idea for this function was taken from Perl and all formatting codes work the same as in Perl. However, there are some formatting codes that are missing such as Perl's "u" format code.

Note that the distinction between signed and unsigned values only affects the function unpack(), where as function pack() gives the same result for signed and unsigned format codes.

參數(shù)

format

The format string consists of format codes followed by an optional repeater argument. The repeater argument can be either an integer value or * for repeating to the end of the input data. For a, A, h, H the repeat count specifies how many characters of one data argument are taken, for @ it is the absolute position where to put the next data, for everything else the repeat count specifies how many data arguments are consumed and packed into the resulting binary string.

Currently implemented formats are: pack() format characters Code Description a NUL-padded string A SPACE-padded string h Hex string, low nibble first H Hex string, high nibble first csigned 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 Z NUL-padded string (new in PHP 5.5) @ NUL-fill to absolute position

args

返回值

Returns a binary string containing data.

更新日志

版本 說明 5.5.0 The "Z" code was added with equivalent functionality to "a" for Perl compatibility.

范例

Example #1 pack() example

<?php
$binarydata = pack("nvc*", 0x1234, 0x5678, 65, 66);
?>

The resulting binary string will be 6 bytes long and contain the byte sequence 0x12, 0x34, 0x78, 0x56, 0x41, 0x42.

注釋

Caution

Note that PHP internally stores integer values as signed values of a machine-dependent size (C type long). Integer literals and operations that yield numbers outside the bounds of the integer type will be stored as float. When packing these floats as integers, they are first cast into the integer type. This may or may not result in the desired byte pattern.

The most relevant case is when packing unsigned numbers that would be representable with the integer type if it were unsigned. In systems where the integer type has a 32-bit size, the cast usually results in the same byte pattern as if the integer were unsigned (although this relies on implementation-defined unsigned to signed conversions, as per the C standard). In systems where the integer type has 64-bit size, the float most likely does not have a mantissa large enough to hold the value without loss of precision. If those systems also have a native 64-bit C int type (most UNIX-like systems don't), the only way to use the I pack format in the upper range is to create integer negative values with the same byte representation as the desired unsigned value.

參見

unpack() - Unpack data from binary string


主站蜘蛛池模板: 常宝霆| 喜欢小红帽的原因怎么写| 昭君出塞简谱| 南北腿王| trainspotting| 赵大勇| 豪斯医生第六季| 诺亚方舟电影免费完整版在线观看| 周华健朋友一生一起走的歌词| 魔都精兵的奴隶第二季| 一路狂奔| 托比马奎尔《兄弟》| 浙江卫视今天节目单| 转正意见评语 | 世界轮廓图| 老司机你懂的视频| 绝顶五秒前在线观看| 死神来了6绝命终结站| 朱莉安妮全集在线观看免费| 电影《在云端》| 人流后吃什么| 电影《神盾局特工》| 高达uce| 重口视频| 烽火流金电视剧全集免费观看| 许华升公个人资料身高多少| 淡蓝色的雨简谱| 真实游戏完整在线观看免费高清| 遍地狼烟| 名剑风流 电视剧| 爱情天梯| 阳巧玥| 浙江卫视是几台| 同志父子第二部叫什么| 忏悔三昧念3遍| 路易斯·帕特里奇| 童年吉他谱原版c调| 生活秀| 让娜迪尔曼| 视觉暂留现象原理| 无锡地图高清版大图|

!!!站長長期在線接!!!

網(wǎng)站、小程序:定制開發(fā)/二次開發(fā)/仿制開發(fā)等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103