How to convert long number (string) in php to 32 bytes buffer?

I am trying to convert this long number: 7066362913544046959379121391986018585750267357944410108207023200264959783199

to 32 bytes buffer.

I was able to do this in python using the following code:

x = "7066362913544046959379121391986018585750267357944410108207023200264959783199"
x_int = int(x)
x_in_bytes = (x_int).to_bytes(32, byteorder='little')

Is it possible to the same in php?

Answer

Solution:

Hello you're going to be using intval method and the pack method.

The code will look like this:

<?php

$x = "7066362913544046959379121391986018585750267357944410108207023200264959783199";
$xInt = intval($x);
$xBytes = pack('L', $xInt);

?>

The 'L' string is the format (unsigned long, always 32 bit, machine byte order). The format string consists of format codes followed by an optional repeater argument. Read more about this in the docs.

Source