Home » Php » php – What encoding to use to send binary data as a string to a server?

php – What encoding to use to send binary data as a string to a server?

Posted by: admin February 25, 2020 Leave a comment

Questions:

I want to send binary data to my server from an android app as a string.

What is the best/proper way to get the bytes correct and characters recognized in php and assigned the correct byte value ?

So what I would like to know is how to do:

Java byte array -> string(same length) -> php byte array.. 
How to&Answers:

So I found out that there are some encodings that can be used in this case, those who will preserve the bytes as they are so we could go with ISO 8859-1.

This needs verification but according to the docs it should be fine. 1 to 1 conversion and no data loss.

Anyways we could also use the BASE64 encoding as @vivek_23 mentioned in the comments. But this adds bytes to the overal length.

So it is up to us. But it seems that a simple 1:1 byte to string conversion is possible.