What is the realtime use of PHP pack and unpack fu

2019-05-31 10:46发布

I saw some file generation codes which uses the pack function.

echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);

What this is doing exactly?

s signed short (always 16 bit, machine byte order)

I dont know why i am not able to understand this in realtime. Am not asking a theoretical answer

When i execute the php , file got generated with some stange characters which is not identified by ms excel.

I just want to know the use of pack(), where to use and how to use?

2条回答
【Aperson】
2楼-- · 2019-05-31 11:24

When would you need to use mysql_connect? When connecting to a MySQL database. Why? To connect to a MySQL database.

When you'll realize that you just got this bad-ass lines of Hex numbers and you need to convert them to ASCII, or when you want to generate a .exe from user input (don't), or when you want to write a Little-Endian encoder, or a bunch of other stuff, you'll use pack.

If you just want to understand what pack does, there's already a question for it. But WHEN to use it? Well, when you want to pack data into a binary string.

查看更多
狗以群分
3楼-- · 2019-05-31 11:35

pack is generally used to generate raw binary data. For example, I saw it used to generate zip files before native functions/classes were available in PHP for that.

查看更多
登录 后发表回答