integer - pack format "Q" on PHP 5.5 / 32 bit machines

190

I would like to implement something as described here: https://webapps.stackexchange.com/a/101153 in PHP. So far the following seems to be working:

encode

return rtrim(strtr(base64_encode(pack('Q', $int64)), '+/', '-_'), '=');

decode

$bytes = base64_decode(strtr($data, '-_', '+/'));
return unpack('Q', $bytes)[1];

Unfortunately this only works on 64bit systems and PHP5.6.3+ where the "Q" format of pack/unpack was introduced.

What possibilities do I have to implement the same function that would work the same on php5.5 64 & 32 bit?

987

Answer

Solution:

As pointed out by @Narf, using this: https://stackoverflow.com/a/41060369/468027 and replacingbase_convert with either: http://php.net/manual/en/function.base-convert.php#106546 or http://php.net/manual/en/function.base-convert.php#109660 solved the issue for me.

People are also looking for solutions to the problem: javascript - i want to display my input and the textbox will be remove at the same time in php

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.