能向我解释有人在PHP中包()函数? [英] Can someone explain to me the pack() function in PHP?
问题描述
我想知道更多关于PHP包()函数:<一href=\"http://fi.php.net/manual/en/function.pack.php\">http://fi.php.net/manual/en/function.pack.php
I would like to know more about the pack() function in PHP: http://fi.php.net/manual/en/function.pack.php
我知道它的数据打包成二进制,但我不知道那些v为V NñC C的意思是,我想知道如果有人能善待并给我一个实际演示时使用的格式?
I know it packs data into binary, but I'm not sure what all those v V n N c C mean and I was wondering if someone could be kind and give me a practical demonstration when to use which formats?
在线文档,变更,缺乏信息,在我看来。
The online documentation, for change, lacks of information, in my opinion.
推荐答案
这些重present你想怎么你正在收拾的数据进行重新二进制格式psented $ P $:
Those represent how you want the data you are packing to be represented in binary format:
所以
$斌=包(V,1); = GT; 0000000000000001
(16位)
其中,
$斌=包(V,1)=&GT; 00000000000000000000000000000001
(32位)
它告诉收拾你想怎么在二进制数据psented数据重新$ P $。
下面的code将证明这一点。请注意,您可以使用不同的解压
从你挤满了数据的格式。
It tells pack how you want the data represented in the binary data. The code below will demonstrate this. Note that you can unpack with a different format from what you packed the data as.
<?php
$bin = pack("S", 65535);
$ray = unpack("S", $bin);
echo "UNSIGNED SHORT VAL = ", $ray[1], "\n";
$bin = pack("S", 65536);
$ray = unpack("S", $bin);
echo "OVERFLOW USHORT VAL = ", $ray[1], "\n";
$bin = pack("V", 65536);
$ray = unpack("V", $bin);
echo "SAME AS ABOVE BUT WITH ULONG VAL = ", $ray[1], "\n";
?>
这篇关于能向我解释有人在PHP中包()函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!