Julia Kovalenko Julia Kovalenko - 1 year ago 95
PHP Question

What is the analogue of struct.pack() in php?

I have a variable id = 1615239032

In python i do

struct.pack('<i', id)

Result is


In php i do

pack('i', $id)

But result is


How to get the same in php?

Answer Source

You already get the same as in Python. It gets corrupted when you try to display it.

If you convert the binary data to something else, for instance their hexadecimal represantions, you'll see that they are the same:

echo bin2hex("x\x97F`");
echo "<br>";
echo bin2hex(pack("i", 1615239032));


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download