Python打包数据到PHP打包数据

发布于 2024-10-26 03:15:57 字数 700 浏览 0 评论 0原文

有人可以帮我将此数据转换为 PHP 等效项: >4siiiiiiiiiiiii8x 它在 Python 中的 struct.pack() 中使用。 这是我到目前为止得到的:N14si13x8
它应该返回: ('P3TF', 272, 64, 6832, 6896, 1426, 8336, 312, 8656, 0, 8656, 0, 8656, 2924384)

PHP 版本结果:

array
  'si13x81' => int 1345541190
  'si13x82' => int 272
  'si13x83' => int 64
  'si13x84' => int 6832
  'si13x85' => int 6896
  'si13x86' => int 1426
  'si13x87' => int 8336
  'si13x88' => int 312
  'si13x89' => int 8656
  'si13x810' => int 0
  'si13x811' => int 8656
  'si13x812' => int 0
  'si13x813' => int 8656
  'si13x814' => int 2924384

仍然需要做对第一个。

could someone help me get this data into the PHP equivalent: >4siiiiiiiiiiiii8x It is used in struct.pack() in Python.
this is what i got so far: N14si13x8
it's supposed to be returning: ('P3TF', 272, 64, 6832, 6896, 1426, 8336, 312, 8656, 0, 8656, 0, 8656, 2924384)

The PHP version results:

array
  'si13x81' => int 1345541190
  'si13x82' => int 272
  'si13x83' => int 64
  'si13x84' => int 6832
  'si13x85' => int 6896
  'si13x86' => int 1426
  'si13x87' => int 8336
  'si13x88' => int 312
  'si13x89' => int 8656
  'si13x810' => int 0
  'si13x811' => int 8656
  'si13x812' => int 0
  'si13x813' => int 8656
  'si13x814' => int 2924384

still need to get the first one right.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦情居士 2024-11-02 03:15:58

我想主要问题是 is 在 PHP 中具有不同的含义。要在 PHP 中重新创建原始列表,这似乎可行:

print_r(unpack("a4header/N13int/x8fill", $p));

给我:

Array(
    [header] => P3TF
    [int1] => 272
    [int2] => 64
    [int3] => 6832
    [int4] => 6896
    [int5] => 1426
    [int6] => 8336
    [int7] => 312
    [int8] => 8656
    [int9] => 0
    [int10] => 8656
    [int11] => 0
    [int12] => 8656
    [int13] => 2924384

我不太确定 x8。它不用于 PHP 中的填充。如果它不适用于真实的数据文件,也许可以尝试 @

I guess the main problem is that i and s have different meaning in PHP. To recreate your original list in PHP this seems to work:

print_r(unpack("a4header/N13int/x8fill", $p));

Gives me:

Array(
    [header] => P3TF
    [int1] => 272
    [int2] => 64
    [int3] => 6832
    [int4] => 6896
    [int5] => 1426
    [int6] => 8336
    [int7] => 312
    [int8] => 8656
    [int9] => 0
    [int10] => 8656
    [int11] => 0
    [int12] => 8656
    [int13] => 2924384

I'm not so sure about the x8. That's not used for padding in PHP. Maybe try @ if it doesn't work on a real datafile.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文