I found several functions defined in http://tw1.php.net/unpack are very useful.
They can covert string to byte array and vice versa.
Take byteStr2byteArray() as an example:
<?php
function byteStr2byteArray($s) {
return array_slice(unpack("C*", "\0".$s), 1);
}
$msg = "abcdefghijk";
$byte_array = byteStr2byteArray($msg);
for($i=0;$i<count($byte_array);$i++)
{
printf("0x%02x ", $byte_array[$i]);
}
?>