PDA

View Full Version : binary->hex/php


tribby
05-15-2001, 02:40 AM
Hi,

I have a Perl script that I need to convert to PHP, and I'm having a little trouble.

In my Perl script I have a string which contains a bunch of binary data. I need to covert that data to hex, and then put two spaces between every two characters (each byte). Later on in the script, I need to have each byte put into it's own element of an array.

In Perl, this is how I did it:

#converts binary to hex
$hexdata = unpack("H*", $binarydata);

#puts two spaces between each byte
$hexdata = join(" ", split(/(\w\w)/, $hexdata));

#puts each byte into it's own element of the @bytes array
@bytes = split(/\s\s/, $hexdata);


Does anyone know how I could accomplish this with PHP? Thanks in advance.

-Tribby

tribby
05-15-2001, 07:43 PM
nevermind, chunk_split was what i was looking for.