Create a byte array to pass to a SOAP service

I need to communicate with a SOAP service written in .Net and they ask me to pass an argument as a Byte Array. I know there is not such thing in PHP, but I am guessing there must be some way of composing this kind of array?

The value to pass is always the same and should correspond to:

byte[]= new byte[0,0,0,0,0,28,184,88]

And I also know the hexadecimal value of it: 0x00000000001CB858

Any ideas please?

That is the opposite and is probably a good starting place.

This will give you your byte array. :slight_smile:

ini_set('display_errors', true);

function create_byte_array($string){
    $array = array();
    foreach(str_split($string) as $char){
        array_push($array, sprintf("%02X", ord($char)));
    return implode(' ', $array);

echo create_byte_array('parameter');
#70 61 72 61 6D 65 74 65 72

For the record: I have seen in other forums a posible solution: to save the binary string into a file, save it on the server and read it directly with PHP. I am implementing this solution.

Thanks for this. I posted my previous post before seeing this one. One doubt: isn’t it this function just translating a string into acii codes and then into hexadecimal? Is this what the .Net byte array represents?

A ByteArray holds, well, an array of Bytes. :slight_smile:

1 Byte contains 8 Bits, and each Bit is either 1 or 0 (binary). Think of a Byte as a string, 8 characters in length and each of these characters is either a 1 or 0.

000101010, 00000001, 11110000 etc …

Each of these Bytes can be represented in Base10 by a number between 0-255.

So we get the ASCII(0-255) value of each character, then convert it to its hexadecimal representation.

If as you say, the data to transport is file data, you may find you can just base64 encode the binary data.

Sorry for rambling :eye:

Thank you for sharing your knowledge! It even seems easy when properly explained!

I will give a try to both solutions and I will post the results here.