duanpuluan0480 2011-04-19 16:47
浏览 71
已采纳

什么是PHP打包和解包功能的实时使用?

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条回答 默认 最新

  • dongnao2048 2011-04-19 17:07
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • dongshi1914 2011-04-19 17:19
    关注

    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.

    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 MICE包多重插补后数据集汇总导出
  • ¥15 一道算法分析问题(关于3-MSAT)
  • ¥15 C++ FLUENT 化学反应速率 编写困难
  • ¥15 Python嵌套交叉验证
  • ¥15 linuxkit+elasticsearch
  • ¥15 兄得萌6.13do题😭😭大一小东西的work
  • ¥15 投不到原始数据,gdal投影代码
  • ¥20 卷积混响的代码帮写。。
  • ¥88 借助代码处理雷达影像,识别任意区域洪水前后的被淹没区域,并可视化展示。
  • ¥100 提问关于声学两个频率合成后主观听觉问题