PHP pack () function
PHP Misc Reference Manual
Examples
Data is loaded into a binary string:
<?php
echo pack("C3",80,72,80);
?>
Running instance »
Definition and Usage
pack () function to load data into a binary string.
grammar
参数 |
描述 |
format |
必需。规定在包装数据时所使用的格式。
可能的值:
- a - NUL 填充的字符串
- A - SPACE 填充的字符串
- h - 十六进制字符串,低位在前
- H - 十六进制字符串,高位在前
- c - signed char
- C - unsigned char
- s - signed short(总是16位, machine 字节顺序)
- S - unsigned short(总是16位, machine 字节顺序)
- n - unsigned short(总是16位, big endian 字节顺序)
- v - unsigned short(总是16位, little endian 字节顺序)
- i - signed integer(取决于machine的大小和字节顺序)
- I - unsigned integer(取决于machine的大小和字节顺序)
- l - signed long(总是32位, machine 字节顺序)
- L - unsigned long(总是32位, machine 字节顺序)
- N - unsigned long(总是32位, big endian 字节顺序)
- V - unsigned long(总是32位, little endian 字节顺序)
- f - float(取决于 machine 的大小和表示)
- d - double(取决于 machine 的大小和表示)
- x - NUL 字节
- X - 备份一个字节
- Z - NUL 填充的字符串
- @ - NUL 填充绝对位置
|
args+ |
可选。规定被包装的一个或多个参数。 |
technical details
return value: | Returns binary string containing data. |
---|
PHP version: | 4+ |
---|
Update log: | Added "Z" code in PHP 5.5, and for Perl-compatible "a" have the same functionality. |
---|
More examples
Example 1
Data is loaded into a binary string:
<?php
echo pack("C*",80,72,80);
?>
Running instance »
PHP Misc Reference Manual