0

I got a request from a friend of mine to convert a simple python script into php but I gotten stuck on a few small things and hopefully someone would be able to help me out alittle. Is there a "easy" way to convert ByteArray in php?

In Python it is

Value2 = ByteArray(Value1)

So in php it would be?

$Value2 = ...($Value1)

Any help on this would be great. Thank you. :)

Bulfen
  • 97
  • 2
  • 9

1 Answers1

1

You don't say what Value1 is, so I'm assuming it's a string.

Use the unpack function. This example converts a string into an array of bytes (int's actually):

 $byte_array = unpack('C*', 'A string here');
 print_r($byte_array);

output:

Array
(
    [1] => 65
    [2] => 32
    [3] => 115
    [4] => 116
    [5] => 114
    [6] => 105
    [7] => 110
    [8] => 103
    [9] => 32
    [10] => 104
    [11] => 101
    [12] => 114
    [13] => 101
)
Martin Wickman
  • 19,662
  • 12
  • 82
  • 106