What is the realtime use of PHP pack and unpack function?

最后都变了- 提交于 2019-12-23 04:07:10

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5719803/what-is-the-realtime-use-of-php-pack-and-unpack-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!