I would like to convert a base64 string to other types, ie integer, float, and char array.
In Java I can use a ByteBuffer object, so it's easy to get values with methods like stream.getInt(), stream.getLong(), stream.getChar(), stream.getFloat(), etc.
But how to do this in PHP?
Edit: I tried the base64-decode PHP function, but this one decode a string, I want to decode numbers.
Edit2:
In Java:
import java.nio.ByteBuffer;
import javax.xml.bind.DatatypeConverter;
public class Main {
public static void main(String[] args) {
ByteBuffer stream = ByteBuffer.wrap(DatatypeConverter.parseBase64Binary("AAGdQw=="));
while (stream.hasRemaining()) {
System.out.println(stream.getInt());
}
}
}
displays 105795
But in php:
$nb = base64_decode('AAGdQw=='); // the result is not a stringified number, neither printable
settype($nb, 'int');
echo $nb;
displays 0, because base64_decode('AAGdQw==') is not printable.