Julia Kovalenko Julia Kovalenko - 4 days ago 6
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

x\x97F`


In php i do

pack('i', $id)


But result is

x▒F`


How to get the same in php?

Answer

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));

Result:

78974660
78974660
Comments