Nate
Nate

Reputation: 28414

Retrieving and displaying RAW data in PHP?

I'm using cURL to get a shipping label from a server and part of the data it returns is supposed to be in RAW format. When I print the data in my browser I see stuff like this:

øøùžÌÏÀÏ3?ü?ðÏÏðÿÌ?ðyø†þ`x€g˜á™øøùžÌÏÀÏ3?ü?ðÏÏðÿÌ?ðyø†þ`x€g˜á™øøùžÌÏÀÏ3?ü?ðÏÏðÿÌ?ðyø†þ`x€g

How do I get that to display in RAW format (i.e. just 1's and 0's) properly?

Thanks!

Upvotes: 0

Views: 137

Answers (1)

Marten
Marten

Reputation: 1356

This is the raw format, just interpreted as a string. What you want is to read the bytes and change every bit into it's own byte.

My first approach would be to split the received string into an array of single chars, then make this an array of ints by applying ord() to every element. Then, while iterating over every bit in every number, you add a '0' or '1' to a result string.

Edit: When you want to pass the data to another service, just send them this string. You are seeing it this way, because your output is interpreting the binary data as a UTF-8 string or so. But the service is expecting an image so they will interpret it correctly.

Upvotes: 1

Related Questions